Hi, thanks for your reply. The problem I mentioned is actually in the UGrabber::TickComponent
, not in UGrabber::Grab()
, which is what you have stated. In the UGrabber::TickComponent
, I will need to use function pointer to verify if the Physicshandle->GrabComponentAtLocationWithRotation
existed without being a null pointer. Physicshandle->GrabComponentAtLocationWithRotation()
will not help in this case as it is a function call, not pointer.
Here is the code for the UGrabber::TickComponent
function:
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
/// Get player view point this tick
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
OUT PlayerViewPointLocation,
OUT PlayerViewPointRotation
);
FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
// if the physics handle is attached
if (Physicshandle->GrabComponentAtLocationWithRotation)
{
// move the object that we're holding
Physicshandle->SetTargetLocation(LineTraceEnd);
}
}