Reposition Blueprint

Hey guys!

So I have been trying to work around this issue I have come across while creating a word processing blueprint. I am trying to create a way to center the text within the blueprint. My thought process is to get the position of the last placed character, divide that number by 2 (to get half the distance from the origin) and then subtract that number from the world position of the blueprint.

Below is my current set up, though the results are less than desirable. Any ideas?

Hello,
What do you use to show your text in your blueprint ? If you use a text render, you can center the text by selecting center in the alignements settings (in detail / text) and your text will be centered on typing update.

I am using meshes for the text.
I wonder how they are centering it.

Below is the blueprint macro I am using to place the letter in relation to the letter infront of it.

I am not sure to have right understand but if you use one mesh for each letter, then you would save each mesh in an array “text”. Each time a letter is added, you add it to your array, then get its length, divide by 2. Function or custom event : for each loop from your array :
Set location = size of letter * (index - return value from divide)
If remainder from divide = 0 : peer : add half a size to each set location.

I suppose that each letter mesh has its origin centered, if not, you’ll have to deal with this offset.

Edit : modified and simplified.

Big picture, it seems like UMG might have more options for good text formatting for you. I believe in either 4.6.1 or 4.7 you can render UMG elements into the 3d world.

Each letters origin is at the bottom left.

I am going to try that array idea. I’ll let you know how it goes!

Here is the blueprint I am getting the letters in. they are cast from a GUI element.

Possibly. I haven’t had much time to keep up with new features.

I couldn’t get the array to work since each letter is a different size, But I got the BP below to work near perfectly.

One problem: The ‘Realign’ bool is telling the BP if it needs to center on X or Y. The issue is that if I have one that needs X and another that needs Y in the same level it will only ever run the true(Y) bool.

A solution could be to create a box parent and attach your meshes to it, you set locations relative to box parent always on same axe and then you rotate box parent facing character like : https://www.youtube.com/watch?x-yt-cl=84838260&v=2U_Y2SxfXr8&x-yt-ts=1422327029

No, Sorry. I guess I didn’t explain well enough what I am trying to do.

The player at the beginning of the game will enter some text. Then throughout the levels this text will be displayed in several areas. But placed almost like signs, it will be static after it is placed. I just need to be able to center it based on the length of the string. Which is working above, but only for the ‘True’ branch. Even if I have one that is set to false.

The above script is in the construction graph with everything else I have shown here. I tried moving everything in the ‘Center Text’ comment box to the event graph and running it on begin play but that didn’t work at all.

Then, why not set and center your text mesh system in a blueprint and set blueprint location / rotation in your level ? (Same than parenting) Sorry i don’t understand the trouble.

Yea, That would be great! But how would I do that?

This?

Just thinking through that math. Wouldn’t it center the first letter on the origin of the blueprint, But then place every letter afterwards to the right of that one?

I had to go away but here is the bp : I used the basic cube shape with a custom event, you’ll have to do with your own typing system but : You create an array of staticmesh component “text” and nothing more in bp :


Edit : Size of mesh is set hard (100 and 50)
I used a custom event and called it from character bp.

Edit 2 : And it will works if you remove letter too but you’ll need to create same event but instead of add mesh, remove mesh and remove in array too.

Awesome! I appreciate all the effort! I will give this a shot soon and report the findings!

I just reminded it : As your origin is down left, you’ll have to do minus half size if remainder not = 0 and nothing if remainder = 0.

Hey! Its working great! :smiley:

Below is the result.

I just had to change the multiply and add values to negative. The words were displaying backwards, with some letters stacked completely on top of each other.
Now I just gotta figure out how to add spaces and kerning back in, since multiple words can be used. The issue being that the letters are not a uniform size.

But as you can see, It is centered! Thanks!

Happy that helped ^^
To have it working with different sizes of letter, the idea i would follow would be to use a second array.
Each new letter is added in mesh array and in size array (from a third array with all sizes registered) then instead of counting number of meshes, you add all sizes in array, divide by 2 and set a var “locate” with negative of it. On loop from mesh array : set letter location with “locate”, set locate = locate + current letter size. And if you add space to your registered array, it’ll be done too.

Alright! I was following along with your idea but I got a bit stuck. I haven’t figured out how to add all of the floats from the array together.

But I was able to store all of the sizes in an array using the Componenet Bounds + Kerning Adjustment.
The spaces are being stored also.(The 6.00000s)

Here is where I am at currently.

Here is my idea, i had to add a few things : there are 3 arrays : “text” the one static mesh added on input, “textsize” the one size of letter added on input and “textref” the one with size references set before start. Each time you add a letter, you need to get the right text size from “textref” and add it to “textsize”. I used 2 meshes one 100 and one 50 (set 0 : 100 and 1 : 50 in “textref” array), and a offset of half the size of current letter was needed. Once again, you’ll have to adapt to your system.
100c572c53ed276ef8dac9710f9a4b1a7b021fd1.jpeg

Edit : i suppose that check text length is useless but in case of i didn’t remove it. I did separate nodes for add meshes and set letter, that could be set in a single function to be cleaner and easier with more entries. Even, letter could be set from an array too (by find index refering to entry)

Awwwwh Yea!

Check it out! I made some minor changes to your build. I took out the center section since I am generating all meshes from the same event. Ran the index in from the initial ForLoop. And I added the top section to get / store the size of the meshes.

Here is the resulting BP.

It works perfectly, Except it is backwards. hahaha.
All of the spacing is perfect though!

When I turn the final Locate negative though. The sentence is flipped, and the letters are the right direction… But now the spacing is all messed up again.

I am going to continue to mess with it. I’ll let ya know what I come up with!

I may try just editing the Kerning Adjustments for each letter to save time.