Game logic lagging behind physics

I have a problem where the Blueprints game logic lags behind the physics simulation.

273929-clipboard-image-16.png

So a disc was shot, it’s path is indicated by the dots. When it hit the surface the hit location was drawn (yellow sphere), a red circle was drawn with the last known transform and the disc was glued to the hit surface with a constraint.
As you can see when this game logic runs the disc has already bounced back so although it’s stuck to the actor it struck, there is a sizable gap between them.

It’s a VR project running at a stable 90 fps so I tried setting the max physics delta time and/or initial avg frame rate to 1/90 ms. Also turned on substepping and async scene, non of them helped.
On the BP side having the tick group on “Post update work” helps a bit, sometimes it’s spot on. However I can’t tell when it actually is so my hackfix (teleporting back to the last known position) is then breaks the whole thing…

Is there a way to keep then in sync cleanly?

To clarify: the yellow dots are a bullet/projectile and the disc is the target that is supposed to get moved back when hit?

Assuming this is correct, what is driving the projectile: UProjectileMovementComponent or are you launching something yourself and letting the physics simulation run it?

Oh no, the dots indicate the path of the disc, ejected from the green spiky thing. It hit the wall at the yellow sphere which I drew as soon as the hit event fired. At that point the gray disc was stopped where you can see now, some distance away from the hit. The red thing is a debug circle, also drawn when the hit occurred, showing the position of the disc the last time the BP ticked. That position also seem off, even if the disc has some thickness. Maybe it’s lagging randomly between 0 and 2 frames…

Ah, okay. I understand now. Would still like to know the answer to the 2nd question: How are you driving the projectile: UProjectileMovementComponent or are you launching something yourself and letting the physics simulation run it?

The disc is a physics mesh with no gravity.

What I failed to understand until now is that no frame or code update is ever executed at the time of impact. The closest two points in time are the last tick and the hit event, but the actual impact still occurred sometime between them.

The physics engine calculated the fact that a collision happened then calculated the result of the collision (the actor bounced back a bit) and updated the world to reflect that. Unreal was never in a state where the colliding actors were actually touching: no frame showed that, no code was run at that precise time.

If we need the actor location at the time of impact then we have to calculate it. A simple solution is, when the hit event fires, taking the hit location and the closest point to it on the actor’s collider. The difference of the two vectors is how much the actor’s locations needs to be offset to get roughly where is should have been at the collision. Of course this doesn’t take rotation into account so the more the actor spins the less correct this calculation will be so one might need a more elaborate solution.