Get static mesh world location from Unreal Editor

Your issue is more likely to be viewport/DPI scaling rather than the static mesh’s location.

There is another version of ProjectWorldLocationToScreen called UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPosition, try that. It accounts for things like viewport/DPI scale//etc which are most likely the cause of your issue.

You’ll need the following include:

#include "Runtime/UMG/Public/Blueprint/WidgetBlueprintLibrary.h"

Although its under UMG, that function doesn’t appear to contain any UMG specific logic so should be applicable for any kind of projection.

I’m trying to draw some text on the screen in AHUD::DrawText() method.

Now, I think, I have find it how to do it: using ProjectWorldLocationToScreen. But now I don’t know which is the WordLocation I have to use.

On Unreal Editor, on my map I have a static mesh that I’m using as reference. I get in the editor its Transform → Location coordinates to use it with ProjectWorldLocationToScreen.


And here is the C++ code:

FVector2D sLoc;
GetOwningPlayerController()->ProjectWorldLocationToScreen(FVector(530.0f, -6.0f, 871.0f), sLoc);

DrawText(PlayerScoreString, FColor::White, sLoc.X, sLoc.Y, TextFont, TextScale);

But this is what I see:

The number 5 is what I draw as text, and the small white vertical rectangle in its left is the cube I selected in the Unreal Editor.

What am I doing wrong? How can I get (or know) the correct World coordinates for the rectangle?

Thanks a lot. I think so. How can I know the viewport and DPI? I was searching but I haven’t found anything about. Anyway, this is my first game. I’m sure I will come back to modified when I have learned more.

By the way, the project is here: