Misaligned World To Screen Space UI Widget

Hi Everyone,

I am trying to align a UI element to world location of an actor in UE 5.1.1 through the “ProjectWorldToScreen” Blueprint node. The result I get from the node as “ScreenPosition” is accurate, but the UI element visually doesn’t align.

When I try to log the result of “ProjectWorldToScreen” node, and the current location of the UI element, they both match.

Below is an image of logs of the result of “ProjectWorldToScreen” node. To be clear I am trying to align the orange square to the white sphere:

Following is my User Widget Canvas & BP setup:

My current resolution is at 100%, however, the same issue persists regardless of the engine scalability setting.

Additionally, if I spawn this square as its own UI Widget in an external Blueprint, and use “SetPositionInViewport” node, the element aligns correctly to the 3D object.

Any help is appreciated!

Are you testing in Viewport, Because thats based on the resolution of the Viewport. Try it in Editor Window or Standalone

1 Like

I have been testing in all different modes, and they all have the same issue.

Does your widget size adjust to the window no matter how big or small the window is

1 Like

I think so, I tested that by putting in a background image that has full scale via its anchors.

When I stretch the windows around, the image does get properly resized. Which leads me to believe that the canvas is scaling correctly.

Then I ask why do you have 2 canvas panels inside that widget

1 Like

I was testing to see if the additional container made any difference. It didn’t unfortunately.

The canvas in this image is also full scale. I’ve removed it since then, but the result hasn’t changed.

Well to figure this out on the screen the sphere position is X 25.798, Y 240.278

Your canvas is set to 1920x1080
so top left would be 0 and the dimention of the square is like 4x5

So where you see it on the screen is accurate i bet if you multiply the location by 4 or 5 it will line up

1 Like

I tried a few multiplier, the issue is worst if I am using different screen resolutions.

If I am on a 4K screen, then the difference between the square and the sphere is further magnified.

my suspicion is that the canvas is using some sort of scale to update its coordinates that isn’t sitting well with the world to screen node.

Instead of Fill Screen try Scale to Screen

1 Like

I think you are projecting world location to absolute screen pixels and not UMG DPI pixels.

In C++ the call is like this to set a world location to a UMG HUD location:

FVector targetWorldLocation = _searchTarget->GetWorldLocation();
FVector2D targetScreenLocation;

UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPosition(_playerController, targetWorldLocation, targetScreenLocation, false);

The import function being “UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPosition()”. I assume there is a blueprint method to do this as well.

3 Likes

Thanks so much! That did the trick!

For someone coming across this in future, You want to use this node :'D :

1 Like

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