- Home /
UI Text does not show when instantiated at runtime.
I really don't understand why this is not working. The exact same code and setup that works in one scene in Unity is not working in my other scene in unity. I've checked and double checked, and I even created a prefab from the working scene, but for whatever reason it just does not want to work in my main scene.
Essentially, I've created a text prefab that Instantiate under the Content transform for my ScrollRect. In my initial test, the text showed up just fine. When I recreated the exact same set up in my main scene, the text.
SOLVED: UGH. In the middle of my rant I have somewhat discovered what the issue is. Basically, the Canvas really doesn't like being SetActive from script. The main reason I did this in my game was because I'm waiting on Steam to make a connection before I initialize the UI. Individual elements can be SetActive from script, and the Canvas can be set active from the inspector without issue. However... if your canvas begins inactive and you try to activate it from a script, any text that you try to spawn via Instantiate afterwards will not render. I don't know why this is, and its stupid, but I at least discovered what the issue was after toiling with it for 4 hours.
Also, it would seem that the Canvas doesn't like to be under a Transform heirarchy, or to have Transforms under its own heirarchy.
Its November 2020 and I just came across this issue! For me it occurred while instantiating Toggle