Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextMeshPro Text Object is not visible in unity gameView

Created a script that adds a textMeshPro text in a gameObject that is child of a canvas. But the text is not visible in the gameView playmode but it is visible on scene mode. The text size is made big and the position is Oth point.

enter image description here

Heres the code to make the textmesh object:

public GameObject g;

// Use this for initialization
void Start () {
    TextMeshPro mText = g.AddComponent<TextMeshPro>();

    mText.autoSizeTextContainer = true;

    mText.text = "Hello there";

    // Set various font settings.
    mText.fontSize = 748;

    mText.alignment = TextAlignmentOptions.Center;


}

How can I make this visible to the camera? and Why its not rendering?

like image 557
bulliedMonster Avatar asked Dec 04 '25 23:12

bulliedMonster


1 Answers

You can place a TextMeshPro GameObject in either world space (Create > 3D Object > TextMeshPro - Text) or UI space (Create > UI > TextMeshPro - Text). As a 3D Object it has a MeshRenderer so it is "in the world" and with the UI version it is "in the screen" using a Canvas.

FYI, your code worked for me, but I had to the using TMPro; directive at the top.

like image 68
ow3n Avatar answered Dec 06 '25 12:12

ow3n