Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How to find TextMeshPro from Canvas by GameObject.FindObjectOfType?

Discussion in 'Getting Started' started by bratan20000, Oct 28, 2021.

  1. bratan20000

    bratan20000

    Joined:
    Oct 28, 2021
    Posts:
    12
    I have GUI that contains TextMeshPro object. How can I get it by using GameObject.FindObjectOfType<TextMeshPro>()? When I try to figure out what it contain, console return me null.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    18,371
    There are two different classes. TextMeshPro is the one that exists in the scene separate from the UI system. What you want is the TextMeshProUGUI class.

    GameObject.FindObjectOfType<TextMeshProUGUI>()
     
    Rumpleson likes this.
  3. bratan20000

    bratan20000

    Joined:
    Oct 28, 2021
    Posts:
    12
    Yeah, thanks, now it works