x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Get static mesh world location from Unreal Editor

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.

alt text

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: alt text

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?

Product Version: UE 4.16
Tags:
more ▼

asked Jul 12 '17 at 02:40 PM in Rendering

avatar image

ViaCognita
30 13 21 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 12 '17 at 04:34 PM

avatar image

VSZ
949 24 29 55

avatar image ViaCognita Jul 12 '17 at 05:44 PM

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.

avatar image ViaCognita Jul 12 '17 at 05:44 PM

By the way, the project is here: https://github.com/ViaCognita/Unreal

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question