Physics Handle not working properly

I’ve implemented a physics handle that grabs a physics object at the hit location from a line trace, but this only seems work when the object I’m trying to grab is already moving, by bumping into it and pushing for example. If the object is stationary, the grab does not work for some reason.

Is there something I’m doing wrong or missing here?

6 Likes

If you print the value of GrabLocation->GetWorldLocation() to the screen, does it look like the location itself is updated? or does it remain stationary?

2 Likes

Hi, just checked and the Grab Location->GetWorldLocation updates correctly and prints out different values depending where the trace hits. Same applies for printing the physics handle target location.

2 Likes

It’s been a while since I did this in Blueprints but I have something very similar in c++.
Compared to that, there are only a few things I can think of right now.

  1. Is the grabbed component colliding with the pawn, resulting in stationary behavior?
  2. Is the grabbed component simulating physics at all times?
  3. Is the grabbed component released at some point, on its own or by calling the Grab method twice?
  4. Physics handle components have some properties to set up for proper interpolation, what do they look like?

My basic setup for a handle component looks like this in c++:

	PhysicsHandleComponent->LinearDamping = 30000.f;
	PhysicsHandleComponent->LinearStiffness = 100000.f;
	PhysicsHandleComponent->AngularDamping = 50000.f;
	PhysicsHandleComponent->AngularStiffness = 200000.f;
	PhysicsHandleComponent->InterpolationSpeed = 17.f;
3 Likes

Thanks for the suggestions.

  1. Disabling collisions made no difference.
  2. Yes, phsics is enabled with nothing to turn it off.
  3. Not as far as I can tell.
  4. I’ve tried playing around with various values and tried the ones you used below, but no difference.

One thing I did notice though is that the issue seems to be related to velocity. If the velocity of the object I’m grabbing is 0, then I can’t grab and move it. Any other value and it works perfectly.

I’ve just had to implement a workaround with a Add Velocity Impulse node after the Grab Component and use a tiny 0.001 impulse amount. Hey presto, it magically works for some strange reason :upside_down_face:

Could be a bug with the rework of the physics system for UE5?

3 Likes

Could be UE5 related yes, I’m on UE4 and I don’t see anything else that could be wrong about your logic. With the same logic I am able to grab stationary physics enabled objects in UE4.

1 Like

Finally figured out the problem (if you’re interested). It was to do with the physics engine putting the physics object to sleep. A simple Wake Rigid Body node in the blueprint and everything works perfectly!

12 Likes

Thank you! I was having the same problem in UE5.

Is there any more info about engine putting physics object to sleep and why?

I was not having this issue with Physics Constraint or adding impulse to object. Only with Physics Handle.

1 Like

I haven’t been able to find much information on physics sleep sadly. All I know is that it helps with performance to not have physics constantly active.

It doesn’t seem to occur in UE4, just in UE5, so maybe it’s because of the re-write of the physics engine for Chaos physics. At this point I’m not sure if it’s a bug or a feature :sweat_smile:

2 Likes

I cant seem to get this fix to work. No matter how many time I try to wake component it doesn’t wake until I walk into the object then I can interact with it?

2 Likes

I am encountering the same issue, and it seems only occurring in UE5.
The hit component only respond to the grab component at location when it is already moving.
I found that by first adding some force value to the object it could be grabbed as intend.


My current workaround


The object details for grabbing

1 Like

Here’s the wake event flow that worked for me:

Maybe try playing with the Sleep Family and Custom SLeep Threshhold Multiplier values on the pickup objects?

I can post my full pickup blueprint snippet if people are interested?

8 Likes

Hey again, I checked the files for 4-26 and there are similar functions to wake up a UPrimitiveComponents, leading to a call (::wakeUp) on a NVidia PhysX file:

\UE_4.26\Engine\Source\ThirdParty\PhysX3\PhysX_3.4\Include\PxRigidDynamic.h

It might be worth checking how this file compares in UE5 and if it’s still called, or replaced by chaos?
@tigerija
The file provides additional information about the sleep mechanic in UE4.26 and 5.0:

When an actor does not move for a period of time, it is no longer simulated in order to save time. This state
is called sleeping. However, because the object automatically wakes up when it is either touched by an awake object,
or one of its properties is changed by the user, the entire sleep mechanism should be transparent to the user.

In general, a dynamic rigid actor is guaranteed to be awake if at least one of the following holds:

\li The wake counter is positive (see #setWakeCounter()).
\li The linear or angular velocity is non-zero.
\li A non-zero force or torque has been applied.

If a dynamic rigid actor is sleeping, the following state is guaranteed:

\li The wake counter is zero.
\li The linear and angular velocity is zero.
\li There is no force update pending.

When an actor gets inserted into a scene, it will be considered asleep if all the points above hold, else it will be treated as awake.
	
If an actor is asleep after the call to PxScene::fetchResults() returns, it is guaranteed that the pose of the actor 
was not changed. You can use this information to avoid updating the transforms of associated objects.

\note A kinematic actor is asleep unless a target pose has been set (in which case it will stay awake until the end of the next 
simulation step where no target pose has been set anymore). The wake counter will get set to zero or to the reset value 
#PxSceneDesc::wakeCounterResetValue in the case where a target pose has been set to be consistent with the definitions above.

*Edit 1. One sec, I actually have UE5 installed already. The Physx file exists there as well and is identical.

*Edit 2. So for most part the calls from the start (UPrimitiveComponent) to the end (Physx) are identical in UE5.

UPrimitiveComponent::WakeRigidBody
	> FBodyInstance::WakeInstance
		> FPhysicsInterface::WakeUp_AssumesLocked
			> PxRigidDynamic::wakeUp

The problem might be with this file:

\UE_5.0\Engine\Source\Runtime\Engine\Private\PhysicsEngine\BodyInstance.cpp

In which a lot of changes have been made and checks have been added. For example:

FInitBodiesHelperBase::FInitBodiesHelperBase(...) {
....
#if WITH_CHAOS
		FPhysicsInterface::SetMaxLinearVelocity_AssumesLocked(Instance->ActorHandle, TNumericLimits<float>::Max());
		....
#endif
....
}

Comparing that to the PhysX comment above:

In general, a dynamic rigid actor is guaranteed to be awake if at least one of the following holds:

* The linear or angular velocity is non-zero.

This already suggests one reason why the component might not wake properly. Nothing looks wrong with it so far but change is change, it’s definitely going wrong somewhere :).

Additional (new) checks can be found in that file which can prevent execution of updating mass properties,

3 Likes

Thank you, you can’t imagine the relief I felt after searching for a fix for an hour… Calling WakeRigidBody worked for me.

1 Like

Thank you!

Got the same here, using UE5. I didn’t know that node and it fixed the problem, my logic was right and I was banging my head on the wall, really thank you!

1 Like

@Muffinchin thank you so much, I think now I will be live longer, I got so stressed about this issue. I m just switching from another engine, thats why I have to thank you so much for the solution. Long life!!!

1 Like

On what file’s BP do I put in those nodes? The game mode?

The nodes went on my first person player BP for me.

Thanks brother it work for me. i wasted hours and i get strating to lose my mind but with your advice everything is fine now. Thanks

Same problem here with UE 5, you saved my day. I was stuck for a long time in this. WakeRigidBody on physics of objects sleeping.