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"

GetViewportSize() and ProjectWorldToScreen() don't match GetMousePositionScaledByDPI?

Hi, I'm having a lot of trouble understanding how the FOV and viewport sizes work at different system resolutions: I'm trying to move and resize world objects based on viewport size.

It started with some FOV experimentation. I placed a plane mesh at (0,0,0), and a camera facing down at (0,0,1500). The camera has an FOV of 90°, which means that the visible area should stretch from (0,-1500,0) to (0,1500,0) along the Y axis because triangles, but this isn't the case - if I place a cube at (0,1500,0), it's off the screen.

I figure it has something to do with resolution scaling, since if I move the cube into view and change the Standalone Window to say 300x900, the cube is smaller and in a different apparent place than in a 600x900 window. I used the BP node called GetMousePositionScaledByDPI and moved the mouse to the viewport edges to compare the values I was getting from PlayerController()->GetViewportSize(), and the BP node gives wildly different values depending on the viewport size, all different from GetViewportSize().

However, after a significant amount of digging I can't find any documentation about accessing the resolution or DPI scaling that is actually happening. I want the camera in perspective mode, but have world objects scaling based on the user's screen size (it's a mobile puzzle game). I also tried going from world to screen and back again with ProjectScreenToWorld and DeprojectWorldToScreen, and I wind up in two different places! like this:

  • Start at (0,-650,0);

  • ProjectWorldToScreen() returns screen position of (170,400) - viewport is 600x900;

  • Line trace from DeprojectScreenToWorld() hits plane at (0,-239.557,50) - plane is at (0,0,0) and 100 units tall;

Clearly there is some resolution scaling happening based on viewport size or something, but for the life of me I can't find any information on what's happening - though I know there's something going on since the BP node has "scaled by DPI" in the name!

I also tried using screen percentage as detailed in this Answerhub post, but it kept giving me a screen percentage of 1.0000, and that's when I had to take a frustration break and turned to community help.

I can't figure out what I'm missing. I would really really appreciate if anyone could point me in the right direction here! Thanks!

Product Version: UE 4.12
more ▼

asked Sep 24 '16 at 08:37 PM in Rendering

avatar image

6 2 6 9

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

0 answers: sort voted first
Be the first one to answer this question
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