Physics handle is basically useless?

After watching the grabber implementation using the physics handle component i wondered what so special about it. it seems to not really do anything since we had to manually update the location of the physics body that we grabbed. so i peeked inside the code and, as i suspected, there was nothing except storing the “Grabbed” object, that is if we are not using physx. so, why should we actually use it?

1 Like

Since you peeked inside the code, try peeking the implementation of ReleaseComponent(). You will see that, if we are not using PhysX, it does nothing. However, calling that method does make our grabbed object fall down. Which means that we are indeed using PhysX, and the handle is not useless.

Very late but still. I didn’t get the answer of vbarata but, if I did get the question, the author is asking why we use grabber if we still have to set the location manually. I.e. if the grabber does not do that for us, what is so special about that? Well, below is a small experiment. We can of course set the location of the actor to the end of the trace line each frame. Let us do that actually:

void UGrabber::Grab() {
	UE_LOG(LogTemp, Warning, TEXT("The E key was pressed!!!"));

	// set the actor in view
	AActor * ActorToGrab = ReturnActorInView();
	if (ActorToGrab) {
		if (!(currentlyHoldingSomething)) {
		currentlyHoldingSomething = true;
		grabbedObj = ActorToGrab;
		else {
			currentlyHoldingSomething = false;
	// set the private variable 'grabbed object' to true
	// another private variable contains the pointer to the grabbed object

As you can see, this function gets the actor in view, toggles the private variable to tell Unreal that this pawn is holding something, and stored the grabbed object privately. Then in the tick component we can do something with the grabbed object like follows:

if (currentlyHoldingSomething) {
		FRotator initialRotation = grabbedObj->GetActorRotation();
		grabbedObj->SetActorLocationAndRotation(debLineEnd, initialRotation);

This sets the location of the grabbedObj to the end of the trace line and its rotation to its initial rotation when grabbed. If you try out this implementation, you will see that the grabbed object does stick to the end of the trace line but is constantly jumping up and down and generally looks very buggy. Even worse, the object will pass through walls, and you will have to handle it with proper procedures: like getting the hit object and telling what to do. If there’s no nicer way around it which I suppose is true, this is not usable at all. This behavior is also understandable: by setting location like that, you disregard any collisions and simply choose the coordinates where the object should be.

So, as far as I understand it, the physcisHandle does not grab the component for us - it is just telling unreal that the object obeys the laws of physics and is currently ‘hanging’ at a point in space. But you have to set this point yourself each time. This is also understandable: you may want to do any kinds of fancy stuff with that point: for example, you may to make it be floating in space.

1 Like

Note that we SetTargetLocation on the physicshandle instead of setting a location on the object. What’s happening behind the scenes, is that the physicshandle is moving the object toward the target location every physics tick, and responding to collisions if they happen. My Room has a doorway that I’m going to hide the trigger volume behind. But with physics handle, the chair is too big to fit through the doorway. How to solve the puzzle? Maybe I’ll add a chainsaw or something that splits the chair in two and then you can carry a half chair through!

Privacy & Terms