View
View

Reputation: 11

Unity SetActive(true) not working for panel

So I have a finishMenu that I'd like to activate when the player finishes the level. I have a UI container (canvas) that contains among other things, my finishMenu. When colliding with a finish pad, the player script executes EndLevel(). It executes a lot of stuff, but it also calls the Finish() function on my UI container:

    public void Finish()
    {
        Debug.Log("Finish Called!");
        finishMenu.SetActive(true);
        Debug.Log("self: " + finishMenu.activeSelf + " hierarchy: " + finishMenu.activeInHierarchy);
        Time.timeScale = 0f;
    }

this is supposed to set it to active, and I'm not getting any errors. The second Debug.Log tells me that finishMenu is activeSelf but not activeInHierarchy, even though the parent gameObject (UI container) is active... Hierarchy I have assigned finishMenu in the inspector, so I don't know what to do...

I have tried debugging with the Debug.Logs and breakpoints, and searching through my code to see if something is setting it to inactive, but I haven't found the answer yet. The finishMenu is supposed to activate, but it doesn't activate.

Upvotes: 1

Views: 521

Answers (1)

Jay
Jay

Reputation: 2946

ActiveSelf measn your call to SetActive was successful, but that will only set the ActiveSelf flag on that one local object, it will not actually become active until ActiveInHirearchy is true.

The fact that it is not ActiveInHirearchy has only one possible cause: That one or more of the object's transform parents is not active.

ActiveInHirearchy is true when and only when an object and all of its parents are ActiveSelf.

From your image, it looks like you need to set the gameObject which is called FinnishMenuPannel to active as well, setting any of its children will not do this, you have to set it on the gameObject itself.

Upvotes: 0

Related Questions