Instantiating Text prefab on overlay canvas, nothing is rendered

So I have a prefab of a regular Text element. Basically I just created a Text from the menu and saved it as a prefab. Then I created a Panel from the GameObject/UI/Panel menu and put it under my Canvas. I added a script on that panel that instantiates the Text prefab, parents it to the Panel using ".SetParent(Transform, bool)’ and sets the text value to something. The Text is not rendered in my scene. If I go to the inspector and disable the Text component and re-enable it, the text appears correctly.

Any idea what is causing this behavior ? I’m instantiating way more complicated UI elements prefabs at other places in my game and it works fine. I’m not sure what I’m doing wrong here.

That sounds like it should work to me. Could you log a bug for us to investigate?

I tried the same thing in another empty project and it works fine. I’ll run some additional tests today and log a bug if it’s still relevant and I can find how to reproduce the bug. Thanks Tim!

I sometimes have to bang on it by calling Canvas.ForceUpdateCanvases() after I finish doing procedural generation stuff (this aspect of the framework is still a bit wonky TBH).

I had another script that was changing the alpha on the CanvasRenderer to zero. My bad.

It’s weird though that disabling/enabling the gameobject or component resets the alpha.

1 Like