How do I center HUD text?

I’m trying to use the draw text node and I was wondering how I can get text to always appear in the center of the screen no matter what size the screen is. Here’s my attempt at doing it which doesn’t really work.

I’m also trying to figure out how to make it so the text automatically scales depending on how large the screen is because right now the text gets cut off if the screen is too small.

On your text widget, set it’s anchor point to the center:

71688-2015-12-23+02_39_25-w_wewlad_.png

Then set the Position X and Y to 0 and both Alignment values to 0.5:

71689-2015-12-23+02_40_36-w_wewlad_.png

Text will always be centered.

Fitting it to the correct screen size is quite a bit more complicated, and is explained in Est_engine’s answer

3 Likes

Hi man !
Here i draw 2 Text in my hud , both almost same size.
But the second dont change with the size of Xhud.

Try to use as scale , your X size of the screen divided by some literal.
Once you checked that it will fit your screen , it should fit any screen.

Lets say we have 3 screen.
1200 get a scale factor of 1

Another one with half of the screen like 600x , will get a scale of 0.5

And another one of 300x, will get a scale of 0.25

What i didnt do in this example is fix the position , because the scale move away the text from the origin.
So you have to put back on the Screen X, Y some adjustment made with a fraction of sizeX of the same type we did here…

Plus the normal Text scaled too much get some horrible result.
Check out this topic , someone figured out how make hd text.

That seems to work however if I wanted to change the size (and make it bigger) then it’s no longer in the center. So how does the position in the screen relate to the size?

Very cool, i didnt know this! thanks man!

I think that the awesome Actioninja already answered you. :slight_smile:

So once I created my text widget, how can I call it and combine it with your blueprint?

Subtract 8 after the divide by 2 nodes.

the OP uses “Draw Text”, there is no text widget with that function obviously

Thank you so much from 6 years into the future. I was really struggling with this as a decent Photoshop user and your information helped me to finally make sense of this.

I came here looking for the same thing. I’ll share what I figured out in case it helps sb. There’s a GetTextSize() that returns the size of the text in pixels. Divide that by two to center.

Here’s the BP in my HUD:

Here’s the result:

I would rather do this in a WBP instead of HUD. Does anyone know if that’s doable? I also have a Selection Marquee that’s drawn in HUD that I would like to have in a WBP if sb can point me in the right direction.

Also set Justification on the Text element to Centered.

image