Did the Text Mesh Pro namespace change?
I updated a project to 2018.2 and when I did, I got the duplicate Text Mesh Pro errors that everyone has been asking about. I followed the instructions and it fixed that problem. I'm now experiencing a problem with the references I had in script to the TextMeshProUGUI components. My "using TMPro;" directive says it's not necessary and shows as an error. All I want to do is be able to modify the TextMeshProUGUI components via script. Did something change? Any help is appreciated.
Answer by Skelly1983 · Jul 13, 2018 at 04:07 PM
The namespace is correct.
for instance to change the text all you would need is the following:
using TMPro;
using UnityEngine;
public class ClassName : MonoBehaviour
{
private TextMeshProUGUI textMeshProUGUI;
private void Start()
{
textMeshProUGUI = GetComponent<TextMeshProUGUI>();
textMeshProUGUI.text = "New text";
}
}
Hope this helps.
Answer by DocMcShot · Jul 17, 2018 at 12:30 AM
So I solved my own problem. I went to the TextMesh Pro option window in the editor (Window->TeshMesh Pro), and imported the "TMP Examples and Extras." I had already imported the Essentials, but apparently, there's something missing from essentials that stops Visual Studio from recognizing the namespace. Anyway, I didn't include the example scenes on my import and it still worked. Hope this helps other. I'm sure it will get fixed eventually :).
Answer by insominx · Feb 19, 2020 at 12:30 AM
Another reason this might not work is if the assembly you're working in does not reference the TextMeshPro one. The image below shows what a valid reference might look like:
Where is this screenshot from? Like where can I find this
Answer by hernan-cl · May 26, 2020 at 01:06 AM
This solution worked for me: https://forum.unity.com/threads/namespace-tmpro-not-found-in-test-runner-test.541387/#post-3570214 Pasting here: The step that I missed which is causing the issue is related to the use of an Assembly Definition in this created test folder.
The solution is to manually edit the .asmdef to add a reference to the Unity.TextMeshPro assembly.
In order to do so, select the file and use the context menu "Show in Explorer" and then open the file in some text editor to make the following changes..
{
"name": "Tests",
"references": [ "Unity.TextMeshPro" ],
"optionalUnityReferences": [ "TestAssemblies" ]
}
Answer by warrenSOLID · Jun 01, 2021 at 07:26 PM
btw, this answer set totally derailed me. When i googled "unity TextMEshPro text" the top result was (is) some old digital natives tutorial which references an old way to handle this. http://digitalnativestudios.com/textmeshpro/docs/ScriptReference/TextMeshPro-SetText.html
basically the old way was "TextMeshPro" but the new way is "TextMeshProUGUI"
(this is in Skelly's top rated answer here. but i didn't read that far. instead i got down into all this assembly definition stuff which wasa misssstakeeeeeee.)
Your answer
Follow this Question
Related Questions
I can't change Text color 3 Answers
UTF-8 UI Text problem 2 Answers
Text font and bold tag issue 0 Answers
TextMeshPro Set Alpha Color 0 Answers
How To Load TTF Font From External File 0 Answers