Make size of world object resolution independent

In screen space it is easy to maintain the pixel size of an element if we change the resolution.

I’m trying to do the same for an object/mesh in world space by adjusting its scale.

But dividing by the values from ‘Get viewport size‘ doesn’t do anything, although it returns the correct value.

‘Get screen resolution‘ is also not helpful as it is not the resolution the game is currently running at.

So, how to maintain the pixel size of an object in world space?

I don’t follow; send a mind-bug..

Trying to picture this but I cannot visualize. You want the on-screen coverage of a thing to always be the same size independent of the screen-res? eg: this thing always takes up x% of the screen, period?

Same size in pixels not percentage-wise.

E.g. an object with size x meters, y meters away from the camera has always a size of z pixels on the screen no matter the game resolution.

oooooooooooooooooooooh hmmm, let me think, i don’t have an answer, but if can i will be back

1 Like

how are you setting the scale? it sounds like thats the problem. i bleieve its called “Set Relative Scale 3D” and you need the mesh component to be the target

That’s exactly the way I’m doing it, triggered from a tick event.

The ‘get viewport size‘ node is marked as ‘cosmetic‘ and ‘client only’.

Thanks!

does it need to be scaled-scaled in the game, or can it be done via WPO in a material?

viewproperties gives you some useful info:

I’m going to use it to generate a Procedural Mesh (a triangle strip) at runtime to keep it the same width (say 3 pixels).

If we could update WPO info when the resolution changes and get the view size in the actor blueprint.

You can use the basic projection relationship that is 1/z no? (Z being distance from view)

If you don’t want to use that calculation, or shaders like mentioned above, you can refer to how the editor code is used to display 2D sprites or 3D widgets. That should give you enough information to know how to go back/forth between world and view to determine the scaling. Two example functions you can look at:

class FDisplayClusterLightCardEditorViewportClient : public FEditorViewportClient
FDisplayClusterLightCardEditorWidget::GetLengthScreenScalar
FDisplayClusterLightCardEditorWidget::GetSizeScreenScalar

Most EditorViewportClient subclasses deal with the world-screen transformations to render custom things.

As you said, using 1/zdepth already got me to the point where everything keeps a size of say 3 pixels no matter where the camera is.

But, increasing the screen resolution makes it 5 pixels. I haven’t found a way to just divide by horizontal screensize for instance.

The example code in the functions above, for example this one, deals with DPI, screen percentages, resolution etc. Do you need Blueprint-code specifically?

FDisplayClusterLightCardEditorViewportClient::Draw

I recall this old thread that was dealing with similar issues. Maybe you can find the BP nodes you need from there.

GetViewportScale is always 1 for me, GetViewportSize has no effect (I can only print those values).

@Denny @Frenetic @ViceVersa Thanks guys. It’s not the end of the world as I’m half a decade away from shipping anyway.

Moreover, having a slider for the user to be able to adjust the width depending on his eye sight and preferences is prob. not a bad idea.

1 Like

This is what you want right? The trick is that you need to determine what dimension of your viewport is what your object should relate to. You need to pick vertical, horizontal, or diagonal size. See attached video for result.

p.s. the logic was put together just to get it working, it’s not perfect, optimized or mathematically great d.s.

2026-01-13 19-28-36.mkv (5.1 MB)

2 Likes

@Danny Using the GetViewportSize from the PlayerController and not the node with the same name from WidgetLayoutLibrary indeed solves the problem, Jesus. Thanks a lot! :+1:

1 Like