Author Topic: [SOLVED] Application.LoadLevel() - GUI from old scene remains  (Read 6836 times)

riksteri

  • Guest
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.png

The 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.png

Please 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?
« Last Edit: July 02, 2013, 05:54:12 AM by riksteri »

VAMflax

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: [SOLVED] Application.LoadLevel() - GUI from old scene remains
« Reply #1 on: August 30, 2013, 02:41:11 AM »
I had this, and it was because I attached a Localization script directly to the UIRoot GameObject. Localization is set to not destroy on load. I moved it out to its own GameObject and all is working again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [SOLVED] Application.LoadLevel() - GUI from old scene remains
« Reply #2 on: August 30, 2013, 05:07:30 PM »
Looks to me like you never clear the screen. If you don't clear the screen, old drawn stuff will remain. Permanently.

Make sure that the first camera to draw is set to clear color or skybox.

UI camera only clears depth by default.