Grabber code crashing editor

I’m curious, why does this crash the editor when running :

void UGrabber::Grab()
{
    auto InReach = GetFirstPhysicsBodyInReach();

    if (InReach.GetActor()) {
	    PhysicsHandle->GrabComponent(
		InReach.GetComponent(),
		NAME_None,
		InReach.GetActor()->GetOwner()->GetActorLocation(),
		true
	 );
    }
}

But this does not:

void UGrabber::Grab() {
    auto HitResult = GetFirstPhysicsBodyInReach();
    auto ComponentToGrab = HitResult.GetComponent();
    auto ActorHit = HitResult.GetActor();

    if (ActorHit)
 	{
        PhysicsHandle->GrabComponent(
		ComponentToGrab,
		NAME_None,
		ComponentToGrab->GetOwner()->GetActorLocation(),
		true // allow rotation
		);
    }
}
1 Like

This line

 InReach.GetActor()->GetOwner()->GetActorLocation()

should actually be the location of the UPrimitive component and not the location of the FHitResults.

1 Like

Privacy & Terms