Positioning Objects in World Space Based Off of Screen Space Positions Lags Behind

I am trying to position a mesh relative to the camera in a first person game every frame as an off screen indicator, and I’m having a lot of trouble with it while moving around. When I am standing still the positions are totally correct, but while I’m moving the positions seem to lag 1-3 frames behind my movement. I’m wondering if anybody can maybe see where in my setup things are getting messed up, because I would have thought this would be much simpler.

The basic idea is that I’m trying to create an off screen indicator to point at locations in world space.

What I do is in my tick function I get the ScreenLocation of my target world location using PlayerController::ProjectWorldLocationToScreen, restrict that to the screen bounds (this part works fine, I can see the values make sense in debug), then I project that adjusted screen position back to world space, and set the mesh’s relative position based off that world position.

Judging by debug output, it looks like my relative positions end up being off of what they should be, which leads me to believe that in my tick function my character’s/component’s world transform is different from the one being used for the World->Screen transform.

I have no idea what I can do to avoid this. My only idea is to get the relative screen bounds in BeginPlay and use those as the basis of setting my component’s relative position instead of trying to do it every frame, but I still want to know why updating things in tick the way I do seems to be messed up.

Any ideas much appreciated.

edit Update: So it looks like the lag comes almost entirely from using the PlayerController deproject functions in tick. An easy way to repro is just to call something like this in your tick function:

FVector worldPoint, worldOrigin, worldDir;

controller->DeprojectScreenPositionToWorld(200.0f, 200.0f, worldOrigin, worldDir);
worldPoint = worldOrigin + worldDir * 50.0f;

DrawDebugSphere(GetWorld(), worldPoint, 10.0f, 10, FColor::Green);

It draws perfectly when not moving, but once you start rotating or anything it clearly drops behind by 1-3 frames.

edit Update 2: Confirmed this also happens when you do the same in Blueprint with ConvertScreenLocationToWorldSpace on epic content examples/sample projects.

Hi mrooney,

I have this problem too and was wondering if you ever found a solution for it.

I did notice that if you add a widget as a component to the actor (via add component), set its User Interface Space to Screen, then call SetWorldLocation on the component once, there is no lag on that widget whatsoever. I’m not sure of the difference yet. Will let you know if I find anything.

Nevermind. I found a workaround by making a new actor component, setting the tick group of the component to Post Update Work and now just call the function on the owner from the component’s Event Tick. Seems to work fine.

I found a workaround about this problem here: ConvertWorldLocationToScreenLocation frame lag? - Rendering - Epic Developer Community Forums

You just need to change the tick group of the Blueprint with the ConvertScreenLocationToWorldSpace Node.

Change it for TG_PostUpdateWork order with this on the begin event.

Now, everything is fluid for me.