# Text objects look slightly differently in viewport and game engine

I have text objects in my scene that I'd like to use in the HUD for a game. When they exist as text objects, I get a different result in a viewport and in game engine once I start playing the game.

I have two separate text objects here

In game engine they are shown bigger, and therefore overlap.

But once I press alt+C and convert them to mesh, they look perfectly the same in game engine as in viewport, just as I want:

But I want them to exist as text objects, because i want to modify them during the game using "obj.text".

So, why are they shown differently when they are the text objects and is there a way to fix that, besides moving them around and figuring the layout out via trial and error?

Version 2.73

Edit1: Just to clarify, my problem is not only about two text objects overlapping each other. If I want to create other interface elements using mesh, they will look exactly the same in game as in viewport. But if I have both mesh and text objects, the texts will bulk up, ruining my interface layout. That's why I'm trying to make text objects look exactly the same in game as in viewport.

I could, of course, just make the text smaller and just run the game several times and adjust the size of the text by trial and error. But that's a pretty tedious workaround ;)

• text object are not treated as objects in bge they are more of strings see this question : why is text pixelated? – Chebhou Apr 28 '15 at 10:46
• I thought about it being connected to resolution, but playing around with it didn't work. I realize that it treats text objects somewhat differently. The problem is, can I make them look the same in both viewport and BGE? – Highstaker Apr 28 '15 at 11:44
• do you use any justification or is it the default settings ,? – Chebhou Apr 28 '15 at 12:18
• Nope, no justification, just your usual "Left" alignment. Also tried with different fonts, didn't work. – Highstaker Apr 28 '15 at 12:47
• hereby I can confirm that I spot the same behaviour and this kind of weirdo is happeing not from yesterday: it affects blenders since 2.69 up to 2.74 as I recall. – piotao Sep 23 '15 at 9:27

Have you thought about displaying only a single text object, and when you replace the new text and or new number string in script use a concatenated string variable which contains the single string.

I don't know Java; but, the concept would be A$="Ammo", B$=numeric $tring (Ammo Count) and DisplayText$= "a$+" :"+B$. Something like that? Then you'd only have to deal with the Font size, vs game engine Font size, and your single Text Object would be variable DisplayText\$ which would look like "Ammo :0" (Of course replacing my simple variables with your own, etc.)

Like I said, I don't know Blender Script language, per se: so, don't know the string concatenator, could be the symbol "&" or semicolon ";" between the strings.

• In Python code, I believe the procedure for concatenating the two strings (to get the new, combined string, the text we want to display) would be something like: "Ammo: " + str(ammo_count_variable). I don't know which function to use to get Blender to assign that new string to the object that displays it, though. – ksoo May 9 '15 at 3:23
• Text objects have a "obj.text" parameter that is exactly that. Doing this that way is not a problem. But my problem is that the usual meshes are show exactly as in viewport, while the text objects bulk up a little bit, making the layout broken in game mode. So I'm trying to find a way to make text objects look equal in both viewport and game modes. – Highstaker May 9 '15 at 5:33
• So, forgive me, as I'm new, so game mode is another viewport mode, which I believe it is like, and I believe when you edit, it's wysiwyg; and so it sounds like a bug. But, I know some modifiers can work in specific modes, but not others. I know if you can submit it as a bug; if you're wrong, and it's actually an implemented feature, they'll sure let you know! I wouldn't want to do this often though. I got semi-smacked on that one once simply because it's not fun to found out the hard way what a dummy I was. lol – Cyberchipz May 18 '15 at 1:40

Setting the origin to geometry (In object mode: 'Object>Transform>Set Origin to Geometry')for text objects helps mostly.

I notice that your viewport is currently in ortho mode, have you tried changing it to perspective mode yet? Usually changing between modes make the mesh look different. Example below.

This photo is a sphere in ortho mode

This shows the same sphere in perspective mode.

Your problem could be that the Text (your amount of ammo) is not being placed to the right of its origin as displayed in object mode, but to the left or center of it when in the game engine. I am not sure if that really is your issue. But if it is, this code should help:

obj["Text"] = obj["Text"].center((5-len(str(obj["Text"])))*5)


You might still need to specify the code to where exactly you need your center to be as this is just what worked for the purpose I used this for in my project. I hope this solves your problem if not it may still be useful somewhere else.