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.

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?

5

1 Answer

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest