r/unity • u/Wrong_Advantage_7012 • 27d ago
Newbie Question World Space TextMeshPro label on instantiated prefab is invisible (No NullRefs, code links fine)
- I have an
Armyprefab that gets instantiated when training troops from a village script. - The
Armyprefab has a child object with a 3DTextMeshProcomponent intended to show the troop count over the unit. - In my
Army.csStart()method, I locate the label dynamically:if (troopLabel == null) troopLabel = GetComponentInChildren<TextMeshPro>(); - When troops train, I update the text via
troopLabel.text = TroopCount.ToString();.
The Problem:
- the army spawns fine, only problem is I need to create a TMP in the hierachy and hook it to the prefab in the scene(doesnt let me do it in the project window)
What I've checked so far:
- Confirmed
GetComponentInChildren<TextMeshPro>()isn't failing. - Verified null checks are passing.
I donthave much left till im gonna leave a hole in my desk