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?
Please see Question 9 in the FAQ from the TextMesh Pro User Forum.
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() does not work.
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.
That was the solution, thanks.
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…
add “using TMPro;” to top of script and use a “TextMeshProUGUI” variable instead of a “Text” one
Thanks, I had no idea what to import in order to use it
i use this:
gameObject.GetComponent<TMPro.TextMeshPro>().text = StringName;
I get the component TMPro.TextMeshPro for Objects and TMPro.TextMeshProUGUI I assume for UI
There are two TMP components. See the following thread which provides information on how to access them.