• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by churi24 · Nov 05, 2014 at 04:21 PM · loadlevelasyncandroid pro

Problems with LoadLevelAsync and Android pro.

I have a problem when the program load scenes. Sometimes works and sometimes not. I have this sequence

Scene1 ---> Scene2 --async--> Scene3 ---> Scene1 ---> Scene2 --async--> Scene3

Sometimes the first LoadLevelAsync works fine and the second not. Scene3 is the game, and it has an scenario, characters, a lot of stuff. When I back from that scene to scene1 and then on scene2 call LoadLevelAsync, always freezes. I dont know why, because, previously the first asyncload worked fine.

The code is this:

 using UnityEngine;
 using System.Collections;
 
 public class LevelLoader : MonoBehaviour {
 
     static public string LevelToLoad="Menu";
     public AsyncOperation async = null; 
     private float progreso = 0.0f;
     private bool ejecutado = false;
 
     IEnumerator Start() {
         async = Application.LoadLevelAsync(LevelToLoad);
         async.allowSceneActivation = false;
         yield return async;
     }
 
     void FixedUpdate () {
         if (async != null){
             progreso = async.progress;
             transform.localScale = new Vector3(progreso, 1, 1);
             if (progreso>=0.9f) {
                 transform.localScale = new Vector3(1, 1, 1);
                 if(!ejecutado){
                     ejecutado = true;
                     Invoke("LoadLevel",1f);
                 }
             }
         }
     }
 
     void LoadLevel(){
         async.allowSceneActivation = true;
     }
 
 }
 

And the call to execute this script is this:

         LevelLoader.LevelToLoad = "Menu";
         Application.LoadLevel("LevelLoader");

Does anybody had problems with LoadLevelAsync on Android?

Regards and sorry, I have a better spanish :P

Comment
Add comment
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

1 Reply

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

Answer by Kyle_WG · Nov 17, 2014 at 02:01 PM

Try changing LoadLevelAsync to LoadLevelAdditiveAsync.

I've had problems too using 'async.allowSceneActivation = false' to delay start using LoadLevelAsync with many freezes and crashes.

When you set your 'ejecutado' to true then just call Destroy(this.gameObject, 1f) so that it will be destroyed when after everything has been successfully loaded. Make sure you parent everything in the level loading scene to this object so that everything is destroyed with it. When you set async.allowSceneActivation back to true it finishes the last part of the load (the 0.1f left over.) so there'll still be a delay. If you destroy immediately then you may get a flicker as a camera will be destroyed before a new one is shown depending on how large the scene is.

Hope it's sorted.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

28 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Application.LoadLevelAsync() causes Unity crash? 2 Answers

How do I stop the GUI from flickering on a new scene? 0 Answers

LoadLevelAsync hiccups on scene switch 0 Answers

Display loading/progress indicator from Start()? 0 Answers

Why does Unity Pro displays game title before splash screen ? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges