Is it possible to get the pose of an actor for every substep of the physics simulation in Unreal Engine 5?
In Unreal Engine 4, you can add a callback function to the OnPhysScene[...]
delegates, e.g.:
primitiveComponent->GetBodyInstance()->GetPhysicsScene()->OnPhysScenePostTick.AddUFunction(this, "SubstepFunction");
or use the FCalculateCustomPhysics
delegate, which was introduced by the following pull request: https://github.com/EpicGames/UnrealEngine/pull/585. Howevery, since Unreal Engine 5, these delegates are only called for every tick, not every substep anymore.
If anyone has the same problem: I solved it using the AsyncPhysicsTickActor
function.
I activated the tick by setting bAsyncPhysicsTickEnabled = true;
in the constructor, then I overrode the function:
virtual void AsyncPhysicsTickActor(float DeltaTime, float SimTime) override;
and implemented it this way:
void AROS2Robot::AsyncPhysicsTickActor(float DeltaTime, float SimTime){
UPrimitiveComponent* primComponent = static_cast<UPrimitiveComponent*>(GetRootComponent());
if (primComponent != nullptr && primComponent->GetBodyInstance() != nullptr && primComponent->GetBodyInstance()->ActorHandle != nullptr) {
Chaos::FRigidBodyHandle_Internal* Handle = primComponent->GetBodyInstance()->ActorHandle->GetPhysicsThreadAPI();
// The transform of the actor with substepping precision:
FTransform worldPos = Chaos::FParticleUtilitiesGT::GetCoMWorldTransform(Handle);
}
}
1 Like