Get Screen Location to World Space

Can anyone tell me exactly how the ‘Get Screen Location to World Space’ node works?

Been messing around with it and I can’t seem to get any coherent values out from the world location output pin.
No matter what numbers I put into the Screen X and Screen Y input pins, it always returns 10.

I presumed that if I put an X value between 0 and the max pixel size, it would return me that value in world coordinates, that doesn’t seem to be the case.

Thanks.

8326-untitled.png

Hey Glenn1990,

What kind of setup are you using to get/print out your World Location?

If you think of it in terms of using a mouse to click a location on the screen or using your finger to touch a screen, a 2D location is returned, which could be passed into your Screen X and Screen Y. This function then converts that XY pair into a 3D World Location, which you can use as your starting location for a Line Trace, and a World Direction, which you would use with a magnitude (basically, a multiplier) to figure out how far you want to draw your line trace to see what you would hit under that screen location.

Hope that helps–let us know if need any more information about this particular functionality.

-Steve

hey steve and thanks for your guide but can u explain a little more about this function??how does it convert a screen location to world space location?whats the criterion??
thanks in regard :slight_smile:

It doesn’t really matter how its done, so long as the result is correct, right?

For what its worth though, here is how it’s done:

What we’re trying to do is draw an intersection ray into the game world. To do this, they figure out where on the screen you clicked. This maps to a coordinate on the current cameras near plane. You can then draw a ray from the camera position to the near plane coordinate. This gives you the direction vector for your ray. They also know the near plane position (because its included with the camera as a part of its view frustum), so deriving the ray position is really easy as well: you just do a linear interpolation on the near planes topleft corner to the bottom left corner with the same amount as the click position is from the top left corner from the viewport window. Now we have a ray which has both a direction and a position. So, what next? We shoot it out into the world and see what objects we intersect with. Usually, this will return everything the ray intersects with, and that’s not necessarily useful (ie, clicking on an actor shouldn’t give you the terrain). The UE4 team gives you a choice to filter out results using “trace channels”. This makes things a teeny bit faster. You are also given the option to limit the length of your ray, so if you know beforehand that the object you’re trying to reach is within 100 units, there’s no need to shoot out a ray with a length of 100000 which will return 100 results.
The ray trace channel will usually return the nearest object it intersects with on the ray. So, if you accidentally have objects in front of the object you’re trying to click on, you’ll get those objects instead of the object you want. Watch out for this.

Still curious on how exactly does UE4 do it? The best way to learn that is by just downloading the engine source code and looking at their line trace code. Alternatively, you can google “Mouse Picking” to see how its done generally.

1 Like