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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

ProjectWorldLocationToScreen don't return the same result on different Quality settings

Hi everyone, I got the following code which I'm running in two different Quality settings (resolution scale 100%-25%)

 PlayerController->ProjectWorldLocationToScreen(CharacterLocation, CharacterLocation2D);
 UE_LOG(YourLog, Warning, TEXT("char location 2d: %s"), *CharacterLocation2D.ToString());

I'm Wondering why this happens and what is the best solution to handle different resolution scales using project and deproject functions.

Thx for reading

Product Version: Not Selected
more ▼

asked Nov 19 '14 at 05:43 PM in C++ Programming

avatar image

184 18 20 34

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

2 answers: sort voted first

Hi Davixe,

ProjectWorldLocationToScreen function returns absolute screen coordinates. The best solution is translate absolute screen coordinates to relative.

For example:

 INT32 width, height;
 PlayerController->ProjectWorldLocationToScreen(CharacterLocation, CharacterLocation2D);
 PlayerController->GetViewportSize(width, height);
 CharacterLocation2D.X /= width;
 CharacterLocation2D.Y /= height;
 UE_LOG(YourLog, Warning, TEXT("char location 2d: %s"), *CharacterLocation2D.ToString())

In this case you have relative coordinates from 0 to 1 with any screen resolution.



more ▼

answered Nov 20 '14 at 10:17 AM

avatar image

Artem Gergel'
245 19 3 20

avatar image Davixe Nov 24 '14 at 03:37 PM

I tried that code, but is happening the same, with resolution scale 25% on the middle of the screen i get x=0.25 and y=0.25 and with resolution scale 100% i get x=0.5 and y=0.5

Other fact is that the GetMousePosition(MouseX, MouseY) function returns the same value on both settings (0.5).

(I'm trying to trace a line on the screen between the position of mouse and the current character location, so this line is different with the differents scales)

avatar image Artem Gergel' Nov 26 '14 at 07:53 AM

Hi Davixe, Just want to clarify, how you changed screen resolution (resolution scale)?

avatar image Davixe Nov 26 '14 at 09:47 AM

In Settings->Engine Scalability Settings-> Resolution scale

alt text

Changing the value of resolution scale modifies the return of the ProjectWorldLocationToScreen function.

avatar image Artem Gergel' Nov 26 '14 at 02:00 PM

We added Screen Percentage. Try this:

 static const auto CVarScreenPercentage = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("r.ScreenPercentage"));
   INT32 width, height;
   pPC->ProjectWorldLocationToScreen(loc, loc2d);
   float ScreenPercentage = CVarScreenPercentage->GetValueOnGameThread() / 100.f;
   pPC->GetViewportSize(width, height);
   loc2d.X /= width*ScreenPercentage;
   loc2d.Y /= height*ScreenPercentage;

Best, Artem

avatar image radu.danciu Feb 18 '15 at 10:12 AM

Ran into this as well in trying to use ViewportToVirtualDesktopPixel.

The problem is that CalcSceneView takes the screen percentage into account, but higher up in the stack the scaling is not reverted before converting from screen fractions into pixels.

While this can be handled like Artem suggested in the case of ProjectWorldLocationToScreen, the same can't be applied in the case of ViewportToVirtualDesktopPixel as this also shifts the coordinates by the viewport offset.

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

It's not broken you're using the wrong thing.

You're supposed to use the [B]Project World Location to Widget Position[/B] node https://i.imgur.com/GYakNNM.png

more ▼

answered Apr 21 '17 at 07:16 AM

avatar image

1.9k 60 50 189

(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