How to use DeprojectScreenToWorld()?

Hi,

I’m make a puzzle game for mobile that involves clicking on blocks arranged in square grids. I would like the blocks to scale according to the user’s phone screen size.

I’ve been getting the size of the viewport like this:

GetWorld()->GetFirstPlayerController()->GetViewportSize(ScreenX, ScreenY);

I then use ProjectWorldLocationToScreen() and DeprojectScreenToWorld() to figure out where the center of the camera is on the screen, and to measure the apparent screen size of the games puzzle pieces (cubes) so I can align them in the correct spots relative to the camera.

However, the values I’m getting for the x,y center of the screen using GetViewportSize() are much different from the values I get from the GetMousePositionScaledByDPI() blueprint node (for comparison). I’m playing in a standalone window that’s 600x900, but the mouseposition node tells me the window is more like 1080x1600.

I use the start and direction vectors from Deproject() to line trace to a static mesh stage which is under the puzzle pieces (it’s a top down puzzle game). I’ve been having problems with line traces hitting the stage in completely the wrong spot based on the screen coordinates I started with, and I think it has something to do with DPI scaling, monitor resolutions, and the viewport, but for the life of me I can’t find the right information about how exactly to deal with viewports and screen coordinates.

Can someone point me towards a solution for moving/scaling objects in the world according to screen size? I see lots of stuff about scaling the HUD, but I’m interested in actually scaling and moving world objects.

Any help is greatly appreciated! Thank you!!!