Edit: Somehow the camera clear flags in the second scene were set to "depth only". Changing that to "solid color" seems to have fixed the problem.I'm using Unity version 4.0.1f2 and NGUI version 2.61e. I seem to have the same problem as the poster in
this old thread, I'm not sure if I should have posted there or made this new thread since that one is so old.
I'm using Application.LoadLevel(string) to change to a new scene, and the GUI of the new scene is initially drawn on top of the GUI of the old scene. The old GUI game objects don't remain in the hierarchy, and in the editor the Scene view also doesn't display them, they are just drawn in the game window. The elements from the old scene can't be interacted with, and if a button was highlighted when the scene changes, it remains permanently highlighted. Resizing the game window causes the old GUI to disappear. It seems to be some sort of refresh issue, where the game somehow doesn't clear the screen, but the last frame of the old scene gets stuck to the screen, and disappears as soon as something (say, a resize event) causes the window to be refreshed.
Let me illustrate:
This is how things look in the old scene.I then click the button, which calls Application.LoadLevel(sceneName), and the scene changes into this:
http://i.imgur.com/mthY2fW.pngThe hierarchy updates correctly, as does the view showing the scene in the editor. The game window, though, displays the GUI from the old scene still, and draws the new scene's GUI on top of it. The button that is highlighted is the button that was clicked, and in the new scene it remains stuck in its green state at all times. The buttons from the old scene can't be interacted with.
I then resize the game window, which apparently causes it to refresh (and the background turns darker, too) and things now look as I'd expect them to:
http://i.imgur.com/0L8ATFW.pngPlease excuse the clumsily mouse cursor pasted from the web, as print screen doesn't capture the cursor.
I have tried
- Just calling Application.LoadLevel() on its own
- Calling UIRoot.Broadcast("Refresh") after calling LoadLevel() while still in the old scene
- Calling UIRoot.Broadcast("Refresh") at the beginning of the new scene
- Calling NGUITools.Broadcast("End") before calling Application.LoadLevel() as instructed here
I'm just getting familiar with and practicing NGUI, I have no idea of any best practices when using it to do this sort of thing, and for example the Refresh broadcasts were just blind stabs in the dark since someone suggested it. I have no idea what, say, Refresh is supposed to do, it just sounded like it might help here.
Does someone have an idea of what could be causing this kind of behaviour?