How to setup a PhysicsHandle correctly?

Well im trying to do simple “Grab an Object and throw it away” stuff.
But im stuck by using PhysicsHandle correctly… Unreal Forum doesnt provide any Solution for me :frowning:

So this is how i did the Setup for the “Grab an Object and throw it away” at the moment.

  1. im doin a LineTraceByChannel
FHitResult ACharacter_Player::GetHitResult()
{
	FHitResult Hit;
	FVector Start = FollowCamera->GetComponentLocation();
	FVector End = Start + (FollowCamera->GetComponentRotation().Vector() * 1500.0f);
	FCollisionQueryParams TraceParams(FName(TEXT("")), false, this);
	GetWorld()->LineTraceSingleByObjectType(OUT Hit, Start, End, FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), TraceParams);
	return Hit;
}
  1. Binding the Inputs to my Grab Function
PlayerInputComponent->BindAction("Grab", IE_Pressed, this, &ACharacter_Player::Grab);
PlayerInputComponent->BindAction("Grab", IE_Released, this, &ACharacter_Player::Release);
  1. Im attaching a PhysicsHandleComponent to my Char

In Header:

UPROPERTY(VisibleAnywhere, Category = Components)
UPhysicsHandleComponent* PhysicsHandle = nullptr;

In cpp:

PhysicsHandle = CreateDefaultSubobject<UPhysicsHandleComponent>(TEXT("PhysicsHandleComp"));

(Headerfile is included btw :slight_smile: )

  1. Now i have created my Grab Function
void ACharacter_Player::Grab()
{
	UE_LOG(LogTemp, Warning, TEXT("Object: %s"), *GetHitResult().GetActor()->GetName());

	UPrimitiveComponent* GrabedComponent = GetHitResult().GetComponent();
	FVector End = FollowCamera->GetComponentLocation() + (FollowCamera->GetComponentRotation().Vector() * 1500.0f);

	if (GetHitResult().GetActor())
	{
		PhysicsHandle->GrabComponentAtLocation(GrabedComponent, NAME_None, End);
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("EMPTY GrabComponent !"));
		return;
	}
}
  1. In the Tick Function i have updated the TargetLocation
FVector End = FollowCamera->GetComponentLocation() + (FollowCamera->GetComponentRotation().Vector() * 1500.0f);
	if (PhysicsHandle->GrabbedComponent)
	{
		PhysicsHandle->SetTargetLocation(End);
	}

And thats it but its crashing and i dont know why :frowning:
I have tested the Grab Function and without any Actor is gettin hit it works just as i want but if i hit an Actor and Press LMB to grab UE4 crashes and i dont know why this is happening …

The LineTrace works fine i have tested it in BP to see the Results and they are like they should be

Its pretty frustrating …

So i have managed to get the Character playing without crashes now but the object still not moves …

Alright i got it to work !

Ive changed from LineTraceSingleByChannel to LineTraceSingleByObjectType and enablöed Simulation Physics… thats it ^^