Auto Resizing HUD elements driven by percentages of screen size

I got tied of having to deal with various screen resolutions and dealing with lots of added code just to deal with a player resizing their screen. I wanted to build out something more like CSS / HTML where you set the HUD item based on a percentage of the screen you want it to use, and position it by the a percentage offset as well. So I built out a system where the developer puts in a series of values, such as Position Offset X and Y, and Percentage Width and Height. The function then resizes the HUD element based on the overall viewport size real time. Here is the Main Function Inputs and outputs.

The target area is used to tell the function where on the screen you want your element to start and end at. This is useful if for example you have a background image of a scroll for your spells and you want your other individual spell elements to stay Confined within it. You will also see a Is Main View Port bool. This is a simple override that sets the Target Area Min and Max values to the whole viewport, so you don’t have to keep plugging them in.

The Element Pos Percent Offset X and Y are used to say what percentage of the Target Area do you want to offset the Element by. So entering something like Offset X 10 and Offset Y 5 would put the elements start position at 10% from the left of viewport, and 5% down from top.

Element Percentage Width and Height is just as it sounds, what percentage of the screen do you want the elements width and Height to be.

The Element Min Width and Min Height are fail guards against small elements getting pushed to being too small. You can set a minimal flat value for both. The function will scale up and down, but if it tries to scale down below those values it stops scaling and uses those as the value. I’ve debated added a Max as well but, not sure it’s really needed.

Horizontal Position and Verticle Position are place holders currently, but they will let you justify elements to the left, center, or right of the screen, and or position them to the top, middle, or bottom. Still working to hammer them out.

For outputs you see you get an Elemental Width and Height, and you get two sets of x and y. The reason is as mentioned before if you are chaining elements together and you have a scroll and you want to keep all the other elements after it within that container the function will pass out the min and max values for x and y so it can feed the next call to it for function to position the inner elements.

Here is a video of it with a “Health bar” as you can see no matter how big or small I make the viewport the health bar stays in it’s location and adjusts it’s size to match the viewports changing size.

Which by using this Function can make things easier for HP bars etc as you can set the Percentage width to be based off the players health and have it resize to show a player losing health as well.

Adding a revised video that shows the health bar within it’s health bar container. This is just the core system at work with rectangles once I get artwork made up for them I’ll swap the rectangles out for textures / materials. Ideally the black bar would be a nice border texture for the player to see relation of how much life they have lost.

Here is a screen shot of my HUD blueprint that shows how easy it is to set one element to be contained / driven by another. In this case the players Health bar stays within the scaling of the health bar container.

Good job. When you release it (If you are going to release it)?

Nice I made something as well based on an idea screen layout that the artist use for their initial layout.

For me all of my layouts are 1920 x 1080 so when we have to add on scene elements we can get the placements from our Photoshop Doc and the game will scale them properly at any other screen resolution. Currently my way keeps squish and squash proportions vs keeping the aspect ratio. I really should update it for that…

Blueprint Helpful BP Functions

The only reason we did not go with percentages is that making layout changes down the line would cause a lot of recalculations. For the artist. Are you running into any similar issues?

May I suggest you wrap that into a function for ease of use. So far I have Draw Smart Texture, Draw Smart Text, and Draw Multiline Text that all intelligently scale.

I like the idea of the Horizon and and Vert restraints. I’m assuming it’s going to pin the rescale to certain parts of the layer?

EX:

Top
Bottom
Left
Right
Relative?