I have created a popup panel with a “Yes” and “No” buttons which pops when pressing the exit button, as is seen this tutorial: Recorded Video Sessions on UI - Unity Learn
In my project:
My exit button (little X in top right) is constant, which means it (actually it’s parent canvas) has a DontDestroyOnLoad() keeping it from scene to scene.
Up until here everything is good and well, but something strange happens when I switch scenes.
It appears as if the “DontDestroyOnLoad” group is behind the newer navigation buttons:
This is despite this script:
private void OnEnable()
{
transform.SetAsLastSibling();
}
worked perfectly for the first scene.
My hypothesis is that unity is creating the new scene’s objects after the panel is set as the last sibling, meaning they appear in front of it. I tried to find functions that may detect when all the objects of a scene has been created (unlikely as it may be), so that I could then re-set my panel as last sibling.
After much despair I’ve tried to find functions that automatically detect weather the object is not SetAsLastSibling, and then make that it will be last sibling when it’s not. Not much was found here either.
Moving in that direction though, I’ve tried what when looking backwards should have been my first though not so very successful attempt:
private void Update()
{
transform.SetAsLastSibling();
}
And as I said, this was my third strike.
All I want is to make what happened in the first scene happen in the others as well. Is there a way around it without duplicating the panel again and again for every scene?


