UI that is under a disabled gameobject won't display when that gameobject is set active

Same as title - I am sure this is quite an old issue though as I already have a workaround for it which is to have the gameobject active but use a script on it that disables it automatically on Start. Then setting that gameobject active after allows the UI to display otherwise it won’t show without that workaround.

Original Post on Discord

by user 103054507105067008

Hi Rob, this would indeed be an old issue being back. Do no UI objects show when you set them active at runtime or just some (e.g. just the text ? )

It does not reproduce here right now. Can you check if your object reference is correct? Codegen for UI objects being referenced might now be exported as RectTransform references. This would be a bug in the codegen (previously all Transform references were exported as Object3D references but UI is now a special case where we actually have a RectTransform component type)
This is my test script

export class ActivateObject extends Behaviour {

    @serializable(RectTransform)
    obj?: RectTransform;

    async start() {
        await delay(1000);
        if (this.obj?.gameObject)
            this.obj!.gameObject.visible = true;
        console.log(this.obj);
    }
}

image.png

I have changed that in a new component compiler where it will now generate a GameObject field instead of a Transform field when you write obj : Object3D in typescript. That’s possibly a breaking change tho when scripts are being regenerated… I’m not sure if we should keep it or roll it back. But otherwise it would not be possible to know for sure what type is expected on export in Unity. So the change is the right one to make I think

Sorry was off on a bank holiday weekend here for a short while, I will get this tested out today

by user 103054507105067008

Confirmed that fixed it, thank you!

by user 103054507105067008