Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: dex_scott on June 13, 2012, 03:46:49 AM

Title: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 03:46:49 AM
Hello,

Im using Application.LoadLevel to change scenes.  This works fine in the editor but when I try it on the iPhone, the UI from the previous scene stays on the screen.  I cant figure out what exactly is going on.

Im not 100% positive this is an NGUI issue but some other topics mentioned about it.  I just upgraded to the latest NGUI hoping to fix it, but no dice.

Any idea what may be causing it to hold on to the other scenes UI?  Im not setting any flags to keep the object on destroy.  Thanks.
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: joreldraw on June 13, 2012, 04:04:15 AM
If you have unhidden objects in your menu sometimes when you modify this, need to reopen each scene and off what you like.
I take this error too, on editor is off but on the tablet appear on.

Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 04:10:05 AM
Im not sure exactly what you mean..Do you mean re-opening the scenes and toggling enabled?
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: joreldraw on June 13, 2012, 04:14:11 AM
Yes, reopen the scene with error  and set Disable what you need again with her childrens.
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 04:23:03 AM
Hmm I tried enabling/disabling everything and re-opening the scenes, but the same problem remains.  On scene change the interfaces "stack" on top of each other.
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: joreldraw on June 13, 2012, 04:31:31 AM
Are you loading this with "Resources.Load" ?
Can attach a snapshot?
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 04:43:45 AM
Thanks for the reply.  Im using Application.LoadLevel to switch scenes when a button is touched.  It "toggles" between scenes.  Im also using this overlaid on a video camera surface and GPS, so not sure if that is part of the problem.  I make sure to stop those services before switching scenes.  Here is some code:

  1. void toggleButtonTouched()
  2. {
  3.         pauseGame();
  4.  
  5.         if (Application.loadedLevel == 1)
  6.         {
  7.                 Input.location.Stop();
  8.                 ((GPS)Camera.mainCamera.GetComponent("GPS")).enabled = false;
  9.                 ((MoveWithCompass)Camera.mainCamera.GetComponent("MoveWithCompass")).enabled = false;
  10.                 Application.LoadLevel(2);
  11.         }
  12.         else if (Application.loadedLevel == 2)
  13.         {
  14.                 Application.LoadLevel(1);
  15.         }
  16. }
  17.        
  18. void pauseGame()
  19. {
  20.         EtceteraBinding.showBezelActivityViewWithLabel("Loading...");
  21.         ((QCARBehaviour)GameObject.Find("ARCamera").GetComponent("QCARBehaviour")).enabled = false;
  22. }
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: joreldraw on June 13, 2012, 04:53:46 AM
Nothing extrange there.

Test on editor withouth full screen and check hierachy when you loadlevel.

Is duplicated?
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 07:37:44 PM
Thanks for the reply.

I tried in the editor and noticed some objects being duplicated.  So I removed them, however it still has the same issues.  Im at a loss really...
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 07:57:25 PM
OK, Ive removed just about everything from the scene.  GPS/Camera/Facebook etc etc.  I literally just have an UIRoot object with a button and this single line of code:

  1. Application.LoadLevel(1);

The UI stays and flickers as the other scene is stacked on top.

Anyone have any idea?  Ive tried restarting Unity, updating NGUI, re-opening scene, enabling-disabling etc.  It works perfectly fine in the Unity editor but not on the phone.
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 13, 2012, 10:14:19 PM
Changed my code to not use LoadLevel anymore.  Now I wrap every scene in a prefab and Destroy/Instantiate per this advice: http://forum.unity3d.com/threads/75635-Reloading-a-level-quickly..LoadLevel-too-slow

Same issue though...Maybe I need to start from scratch?  Have a deadline tomorrow, hopefully I can get this figured out!
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: joreldraw on June 14, 2012, 01:36:59 AM
Try Loading async and waiting full loading...im using this without any problem on Android 2.1 and 3.1

IEnumerator Start() {
     AsyncOperation  async = Application.LoadLevelAsync(Level);
     yield return async;
       
    }

Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: dex_scott on June 14, 2012, 02:05:51 AM
Thanks for the reply.  I changed it to load asynchronously but I still have the same issue :(
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: PhilipC on June 14, 2012, 02:20:59 PM
What version of Unity are you using? I just helped someone else who what having issues (not the same one) who was using 3.5.1 and upgrading to 3.5.2 solved his issue.
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: Rafe on March 24, 2013, 09:48:17 PM
Hi,

We are experiencing something similar. Only on iOS so far, not in the editor.

I am in Unity 4.1.0f4. I am fairly up-to-date on nGUI but am updating to v2.3.3h now.

When our main menu loads, the screen is empty. Then the title labels and buttons fly in from off-camera (title scale + position, buttons position only). When I don't use the Tweens, it works fine. When I do use the Tweens, the whole screen flickers. Even if I hit the play button through the flickering, the next level loads and the flickering continues. If the player dies chooses to quit to the main menu, everything starts looking right again.

I have the scene stripped down to just the UI root, panel, camera and a single button. I even tried a "loader" scene (built as the entry point and just has a little script to load the main title menu). We tried both LoadLevel and LoadLevelAsync with the same result. We are using NGui's LoadLevelOnClick component for the buttons (uses async I believe?)

My theory is it has something to do with geometry generation of camera, or large geo. I'm not sure. Even if the elements load on screen, and I use a co-routine to a wait a second and then activate the Tweens, it flickers once they activate.

Any idea what else I can try to debug this?

Cheers,
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: yuewah on March 25, 2013, 07:13:14 AM
u try to put Debug.Log after Application.LoadLevel , and see how many time LoadLevel is called on the iPhone. It will have strange problem in iPhone only if LoadLevel is called multiple time within a short period of time
Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: Rafe on March 26, 2013, 01:04:05 PM
I woke up this morning with the answer (very strange feeling)... I had removed the maincamera. Adding it back in fixed the issue.

It would be great to add a warning for this since it is obscure & works fine in the Editor (assuming someone else can reproduce and confirm).

Title: Re: Application.LoadLevel causing very strange behavior on the iPhone
Post by: arun02139 on June 13, 2014, 11:13:22 AM
I just want to add that adding the main camera back in also solved this (or a very similar) problem for me :o

Happy coding, all =)