Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by saldavonschwartz · Jun 24, 2015 at 10:06 PM · unity5loadlevelasync

Reloading scene asynchronously causes stutter as the scene seems to restart a few times in a row.

I have a project with a single scene. When my player dies I reload the scene. I've tried reloading the scene asynchronously, as in:

 Application.LoadLevelAsync(Application.loadedLevel);

But both in the editor and iOS what ends up happening is the scene seems to star over 3 times in a row. That is, the scene shows up on screen and a UI animation stars (which is the first thing that happens in my scene), but immediately the scene restarts 2 more times, until the 3rd time, where the scene does stay loaded and the rest of the game proceeds as usual.

The only thing I gathered so far is that when running on iOS, when this stutter / multi reload happens, I get the following in the Xcode console:

 (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
 
 Built-in UI layer disabled. Causes: [Requires OpenGL]

If instead I load the scene synchronously, it takes longer to load but I get the scene restarting only once, as I'd expect. Also, on a side note, debug mode seems enabled even though I'm making a release build :/

Any thoughts?

Just in case, here is what I assume is the relevant code. This is the code that kills the player and restarts the level, attached to a 'trap' object that the player can collide with:

 IEnumerator killPlayer(GameObject player) {
     player.transform.parent.gameObject.GetComponent<PL.Model.Vehicle>().Destroy();
     player.transform.parent.gameObject.GetComponentInChildren<AnnouncementsUI>().announce("GAME OVER");
     yield return new WaitForSeconds(1.5f);
   
     AsyncOperation reload = Application.LoadLevelAsync(Application.loadedLevel);
     reload.allowSceneActivation = false;
     
     // Scene fades to grayscale:
     ColorCorrectionCurves[] curves = player.transform.parent.gameObject.GetComponentsInChildren<ColorCorrectionCurves>();
     int curvesDone = 0;
     while (curvesDone != curves.Length) {          
       foreach (ColorCorrectionCurves curve in curves) {
         curve.saturation = Mathf.Lerp(curve.saturation, 0f, Time.deltaTime);
         if (curve.saturation <= 0.01f) {
           curvesDone++;
         }
       }
       
       yield return null;
     }
     
 //    Application.LoadLevel(Application.loadedLevel);
     reload.allowSceneActivation = true;
   }


And this is the code that triggers the first animation when the level starts:

 public class AnnouncementsUI : MonoBehaviour {
   public Text announcement;
   public Driver driver;
   private Animator animator;
   private int announceState;
   public bool startGame;
   
   void Start() {
     driver.autoThrust = false;
     animator = announcement.GetComponent<Animator>();
     announceState = Animator.StringToHash("CountDown");
   }
   
   void Update() {
     if (startGame) {
       startGame = false;
       StartCoroutine(CountDownToGame(3));
     }
   }
   
   public IEnumerator CountDownToGame(int count) {
     for (int i = count; i > 0; i--) {
       announce(i.ToString());
       yield return new WaitForSeconds(1f);
     }
     
     announce("Go!");
     driver.autoThrust = true;
   }
   
   public void announce(string text) {
     announcement.text = text;
     animator.Play(announceState, -1, 0f);
   }
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zach-r-d · Jun 25, 2015 at 12:27 AM 0
Share

Could you post more of the code that does the async load? Is it the same as your last question?

avatar image saldavonschwartz · Jun 25, 2015 at 12:44 AM 0
Share

yeah it's the code from the last question. I made a new question cause assu$$anonymous$$g this is like SO, questions should be very focused. Assume that I removed that while you suggested I remove (which btw, I still think it should work with the while but thats' a different story). So the level loading happens every time. What I see is first that the animations taking place while the level loads are definitely being affected by the background loading of the scene, and when the scene is finally done loading, it shows up on screen, starts the first animation and stutters, then reloads the scene again and again and finally allows the scene to keep going.

avatar image zach-r-d · Jun 25, 2015 at 01:06 AM 0
Share

Got it. And as a side note, indeed, UA is literally SO for Unity (used to even be on StackExchange). And I agree, that while loop should absolutely work, but .progress being wrong is a bug in Unity that has to be worked around.

Could you try putting a print right before the LoadLevelAsync to deter$$anonymous$$e whether it's getting called multiple times or the problem is somewhere else?

avatar image fafase · Jun 25, 2015 at 05:44 AM 0
Share

The following won't fix but may help. Remove the Update and startGame. You don't really need it and just add:

 private bool sentinel = false;
 public void SetStartGame
 {
     StartCoroutine(CountDownToGame(3));
 }
 
 private IEnumerator CountDownToGame(int count) {
      if(sentinel == true){
           Debug.Log("$$anonymous$$ultiple calls");
           yield break;
      }
      for (int i = count; i > 0; i--) {
        announce(i.ToString());
        yield return new WaitForSeconds(1f);
      }
      
      announce("Go!");
      driver.autoThrust = true;
      sentinel = false;
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by saldavonschwartz · Jun 25, 2015 at 12:06 PM

Pretend this never happened...

Basically the problem was that I was starting killPlayer (the coroutine) from OnTriggerEnter and the method was firing 3 times (most probably because of the DontGoThruThings approach, aka, raycasting to get collisions at higher speeds). Since StartCoroutine can be called multiple times, each time dispatching a new copy of the routine, I was literally dispatching 3 routines, each loading the level again.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading Progress using UNET 2 Answers

Loadlevel.async stops at ~90%? 4 Answers

Using LoadLevelAsync to load a level in the background , but initiate the level changing after something is done 1 Answer

Loading Scene in between two scene for web player. 0 Answers

Unity 5 assetbundle Java.net.UnknowHostException 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges