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.
  2. Dismiss Notice

TextMesh Pro How to Create Object Reference to Text Mesh Pro Object

Discussion in 'UGUI & TextMesh Pro' started by toridominowski, Nov 22, 2017.

  1. toridominowski

    toridominowski

    Joined:
    Nov 7, 2016
    Posts:
    9
    I have been trying to access a GameObject's TextMeshPro component from within a script I am writing, but I can't seem to find the proper namespace to allow it. "using TMPro" does not add anything useful, and there are no valid variable types that seem to be related to TMP. What is the proper namespace that I must use in order to create a variable of the type of a TMP Input Field?
     
    virgiliu likes this.
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Please see Question 9 in the FAQ from the TextMesh Pro User Forum.

     
  3. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Any suggestions how to get reference with Unity2018.2.0 ???

    Using TMPro namespace seems not necessary any more, but still can´t get it.
    GetComponent<TextMeshProUGUI>() does not work.
     
    Last edited: Jul 23, 2018
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Using the TMPro namespace is still necessary and nor has the API changed so accessing a component is done as it was before.

    On the other hand, the TMP UPM package (actually all packages) use the new Assembly Definition feature and as such if you are using assembly definitions of your own on your scripts, you will need to manually add a reference to the Unity.TextMeshPro assembly. See the following post as well as this other one about this.

    There is also a potential issue in also related to Assembly definitions where Visual Studio gets confused. Please make sure that you are using the latest release of Visual Studio 2017 which is 15.7.5.
     
    Fewpwew130 likes this.
  5. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    That was the solution, thanks.
     
    Stephan_B likes this.
  6. TheAngryGuy

    TheAngryGuy

    Joined:
    Dec 9, 2016
    Posts:
    6
    I'm having the exact same issue with Visual Studio Code and Unity 2018.1.7f1

    I can't see any of the assembly definition files (i'm not explicitly using them) and the TMPro namespace refuses to the found.

    @Stephan_B, what's going on?

    Thank you

    EDIT: The problem has magically disappeared today...
     
    Last edited: Aug 1, 2018
    Fewpwew130 likes this.
  7. tuesday437

    tuesday437

    Joined:
    Aug 12, 2018
    Posts:
    1
    add "using TMPro;" to top of script and use a "TextMeshProUGUI" variable instead of a "Text" one
     
  8. tmendez

    tmendez

    Joined:
    Oct 12, 2015
    Posts:
    39
    Thanks, I had no idea what to import in order to use it
     
  9. TonyTCB

    TonyTCB

    Joined:
    Aug 4, 2020
    Posts:
    1
    i use this:
    gameObject.GetComponent<TMPro.TextMeshPro>().text = StringName;

    I get the component TMPro.TextMeshPro for Objects and TMPro.TextMeshProUGUI I assume for UI
     
  10. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    There are two TMP components. See the following thread which provides information on how to access them.