• 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 dashticle · May 09, 2017 at 05:20 AM · scenescene-loadingstartasyncloadlevelasync

Display loading/progress indicator from Start()?

I'm making a simulator which involves dispersing objects randomly over the NavMesh. I have code for getting random point on the mesh, and I am caching 200 - 400 such positions in Start().

However this, along with other heavy lifting done in other Start methods, like Instantiates into object pools etc., cause a long delay at the start of the program (20-40 seconds).

What is the best practice way to provide a loading/progress indicator for work done in Start()? I already implemented the loading bar from here: http://answers.unity3d.com/questions/457594/how-to-make-a-progress-bar-for-loading-next-scene.html , but this jumps straight to 90% and then freezes while the Start() work is done (I understand this is because there's is not much in the way of assets to load, but lots happening in the Start() of scripts.

Is there a way even I can change the text in the load bar from a Start() method after calling loadLevelAsync? The scene loading script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class SceneSelector : MonoBehaviour {
 
     public Texture2D white;
     public Texture2D stripes;
     public Texture2D window;
 
     private AsyncOperation async;
 
     private Object loadBarPrefab;
     private GameObject loadbarObject;
 
     private GUIStyle loadingBarStyle;
 
     private int windowWidth = 400;
     private int windowHeight = 200;
 
     private float barWidth = 300;
     private float barHeight = 50;
 
     // Use this for initialization
     void Start () {
         loadBarPrefab = Resources.Load("LoadingBar");
         loadbarObject = (GameObject)Instantiate(loadBarPrefab);
         loadbarObject.SetActive(false);
     }
 
     public void RestartCurrentScene()
     {
         async = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);
     }
 
     void OnGUI()
     {
         if (async != null)
         {
             GUI.DrawTexture(new Rect((Screen.width / 2) - (windowWidth / 2), (Screen.height / 2) - (windowHeight / 2), windowWidth, windowHeight), window);
 
             GUI.DrawTexture(new Rect((Screen.width / 2) - (barWidth / 2), (Screen.height / 2) - (barHeight / 2), barWidth, barHeight), stripes);
             GUI.DrawTexture(new Rect((Screen.width / 2) - (barWidth / 2), (Screen.height / 2) - (barHeight / 2), barWidth/*maybe100*/ * async.progress, barHeight), white);
             GUI.skin.label.alignment = TextAnchor.MiddleCenter;
             GUI.contentColor = Color.black;
             GUI.Label(new Rect((Screen.width / 2) - (barWidth / 2), (Screen.height / 2) - (barHeight / 2), barWidth, barHeight), "***Loading: " + string.Format("{0:N0}%", async.progress * 100f) + "***");
         }
     }
 }
 

Is it possible to pass a message from a script's Start() to a load bar/message in this way?

Thanks!

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Loading Muiltiple Scenes Async 0 Answers

How to make Awake and Start get called in order with additive scenes? 1 Answer

Holding SceneManager.LoadSceneAsync until a button has been pressed? 1 Answer

How can I get the last frame before a new level was loaded ? 1 Answer

Load and run scene in background 1 Answer

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