Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Cogniad · May 15, 2019 at 07:02 AM · load sceneasyncloading screenloadlevelasync

Loading Bar for Awake Function

Hello, I have a pretty simple loading bar currently in a main menu scene.

     IEnumerator LoadingScreen(string sceneName)
     {
         loadingScreenObj.SetActive(true);
         aSync = SceneManager.LoadSceneAsync(sceneName);
         aSync.allowSceneActivation = false;
 
         while (!aSync.isDone)
         {
             loadSlider.value = aSync.progress;
             if(aSync.progress == 0.9f)
             {
                 loadSlider.value = 1f;
                 aSync.allowSceneActivation = true;
             }
             yield return null;
         }
     }

This is all fine and dandy, and works well enough (I followed a tutorial to get the effect). The problem is that the game scene that it loads into has an Awake() function that takes about 20 seconds to get through because it generates land and initializes a lot of scripts.

After a bit of research, I'm still confused. How do I get it so that the loading bar in the main menu includes this awake function in the game scene? Can I make it so that Text in the UI of the main menu scene changes based on the part of the super long awake function?

Is any of this even possible?

Comment
Add comment · Show 1
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 Jack-Mariani · May 15, 2019 at 07:25 AM 0
Share

This is a duplicate of this question: https://answers.unity.com/questions/1631829/loading-bar-in-different-scenes.html

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Pangamini · May 15, 2019 at 08:48 AM

The only solution here is: Don't create Awake() function that takes so long. Make it initiate the process, but if your Awake() blocks for 20 seconds, there is no way how you can render its progress (no frame is rendered until the Awake() finishes (maybe some native rendering plugin could do it, just a blind guess) What you can do is to split your awake to a coroutine that yields frequently, allowing the engine loop to continue. Of course, you'd need to prevent your active game objects to start 'living', either by postponing their creation (spawning them last) or setting a timescale to 0, so nothing really happens in that time (your characters don't fall through unfinished level).

From the coroutine, you can even start some other threads (if your level generator includes code that can be executed on other threads), and wait for the thread completion in the coroutine.

Sometimes you have a level with many small awake/start calls, but together are very slow. You can avoid that by: Off-loading the awake/start work, pre-bake the situation. But this is not possible if you generate things procedurally. What I did on one project was similar, a coroutine that activates gameObjects in batches in a coroutine. This is possible, if your awake/start objects don't depend entirely on the order of activation of other objects (eg. you don't care that one character had awake and start called before the other one had awake called).

In conclusion, there are options, but you have to split the execution between frames.

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

108 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 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 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 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

Loading Bar in Different Scenes 1 Answer

Loading Muiltiple Scenes Async 0 Answers

GameManager Problem with loading scene 1 Answer

How to create a loading screen at the beginning? Load asynchronous not working 0 Answers

Do we need pro version for loading progress in unity 5 ? 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