ProjectWorldLocationToScreen delayed by one frame? Rubbery UI.

Hi,

We’re using ProjectWorldLocationToScreen to pin some 2D Slate graphics to actors on screen. But the camera projection seems to always be based on the last frame, resulting in 2D graphics that lag the actors on screen, especially visible if they change direction quickly.

Worse, we only react to specific changes, i.e. we only re-pin a 2D Slate graphic when the camera changes to another locked position. But even though the camera has moved, projecting will still be based on the old camera position, unless we wait one tick.

It seems that Unreal only computes whatever is necessary for ProjectWorldLocationToScreen at the next tick.

Is it possible that all games with actor-HUDs actually have the position of the HUD delayed by one frame?

We’ve tried every example we can find, exhausted the AI, and dug through the engine source. ProjectWorldLocationToScreen will simply not return a new projection for a moved camera until after the next frame.

Steps to reproduce:

  • Within one blocking code execution:
  • Move camera to a different position.
  • Use ProjectWorldLocationToScreen to get the 2D position of an actor.
  • Observe that you get a 2D position based on the old camera position.
  • Wait one tick.
  • Observe that you now get a correct 2D position.

How do people solve this?

Per

Hi,

I’ve solved it, and since there’s something to learn, I’m leaving the answer here.

Slate relies on projection matrices in the current camera, and these don’t get updated until the next tick. So if you intend to programmatically move the camera and immediately project world to screen in order to position e.g. HUD items over Actors, you need to force the matrices to update, using:

PlayerController->UpdateCameraManager(0.0f);

The tooltip for this says “Update the camera manager; this is called after all actors have been ticked.”.

Putting this immediately after any programmatic setting of camera actor transforms will allow you to use ProjectWorldLocationToScreen immediately.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.