Instanced Materials and Gameobject.visible

Just bummed into something: Meshes with instanced Materials does not hide when gameobjects visibility is set to false. Is this intentional?
Also, setting “activeself” is not behaving the same as “visible”. This caused confusion as well, this should be noted somewhere if not already.

Original Post on Discord

by user 334342083445784576

No this is not intental, sounds like a bug to me.

About not behaving the same: can you shortly describes what behaviour you see when setting activeSelf vs visible and what you would expect for each case instead?

Yes, if I debugged correctly, calling GameObject.SetActive(true) from a UnityEvent and reactivating the GameObject with activeself = true seems to result in all following SetActive() calls on the object doing nothing, until I set activeself to false again.
Now, that I debugged this with structure I feel dumb for mixing the calls ;).

by user 334342083445784576

I’am here on the same issue. Maybe because I have the honor to maintain Poddens project. :slightly_smiling_face:
My problem is, that I want to react on gameObject.visible not in Unity itself, but back in typeScript.
Let me explain. We have typeScript that toggles some UI Elements in the threejs canvas via this.uiPanels[i].gameObject.visible = false; But we want to toggle some HTML elements in the sourrounding website as well, so I made a TS script to try to toggle the HTML Elements via CSSSelector.

    @serializeable()
    htmlSelector: string = "#btn-hide-cube";
    private element? : HTMLElement;

    onEnable() : void { this.showElement(true); }
    start(): void { this.showElement(true); }
    onDisable() : void{ this.showElement(false); }
    onDestroy(): void { this.showElement(true); }

    private showElement(state: boolean) {
        if (!this.element)
          this.element = document.querySelector(this.htmlSelector) as HTMLElement;
        if (this.element) {
            if (state)
                this.element.style.visibility = "visible";
            else
                this.element.style.visibility = "hidden";
        }
    }

But aside of start() no other function will ever be called when gameObject.visible changes. So the question is, how can I respond to gameObject.visible?

by user 689743366355025931

Hey :wave: Can you make sure that showElement is not being called by adding a console log right on the beginning of the method?

The code can possibly do nothing if the element gets undefined and querring the document would not find the element. Possibly can you add a check for that right after the querry selector and console.error() to notify you that the element was not found?

Hi, I have a console log in all 4 lifecycle functions, but cut it here for better readability and Only when the applications starts the log in start() fires.

by user 689743366355025931

Ok, that’s a bit different issue then this thread is about, can you please create a new forum post? Thanks :slight_smile: