Download

Problems with zOrder when adding a new widget to the viewport

I’m working on a game that has numerous levels for the player to complete. I have a level selector screen that has an in-game menu and multiple “world” widgets that I animate in and out when the player changes worlds. But the in-game menu stays. It works until the player goes through all the levels in the first world and I transition to the next world.

I add the new world widget to the viewport and start the exit animation for the old world and when the out animation is complete I remove it from the viewport. The problem is when I add the new world widget to the viewport the in-game menu that is part of the level selector is now hidden. I set the zOrder of the in-game menu to 50 and the zOrder of the items in the first world to 0 and the second world to 1 so the in-game menu should be shown above them. But after I call add to viewport on the new world widget, it covers the in-game menu. I tested that this is the case because after calling add to viewport on the new world, I called remove from parent and then add to viewport on the level selector and the in-game menu is displayed. So regardless of zOrder, add to viewport will add the item over everything else. Doing this seems like kind of a hack and I also get a warning in the log that the level selector was already added to the screen. Is there a better way to make sure the in-game menu is always above the different world widgets I have? If not is there a way to do this without getting this warning. I know its just a warning but I like to try and keep my logs clean of unnecessary stuff.