I’ve been stuck for a couple of days with the simplest task instructor ben gave which was simply changing the text of the text mesh in the editor using our script.
The problem is. I couldn’t find any object called Text mesh so I it was what’s throwing me problems like “NullReferenceException” and more because this line
textMesh = GetComponentInChildren<TextMesh>();
simply couldn’t find a “TextMesh” since I am using “TextMeshPro”
Hence i tried using GetComponentInChildren<TextMeshPro>();
BUT this only gave me an error since it couldn’t find such a method.
I later found out that the Solution to this was simply to include this library
using TMPro;
to make searching for “TextMeshPro” available using
GetComponentInChildren<TextMeshPro>();
Now the reason why i created this article apart from helping whoever is stuck for the same reason is… Why am i even allowed to make unity search for TextMeshes if i can’t create a Text Mesh… or is there a way to Create a text mesh that i’m not aware of.?
ps. i’m using Unity 2019.4.3f1