- Home /
Progress not showing for items in Start()
So I have two scripts that are run at Start(): PlacePeople and PlaceCars that scatter people and cars in my scene. It can take a while, so I wanted percentage bars to show you why the game wasn't running yet.
When I try to use a percentage bar with the SceneManager.LoadSceneAsync, it gives me a quick percentage as the scene loads, but when I dismiss that, the PlacePeople.Start() and PlaceCars.Start() routines are then called, so we still have to wait. I had hoped it would not be loaded until all of the Start() routines were complete, but that is not the case.
When I try to place a canvas and UI in the scene, showing at start, and try to update the PB there, the whole scene loads and the the PlacePeople and PlaceCars runs before the Canvas is displayed.
So, how can I display a Canvas that can be updated from PlacePeople.Start() and PlaceCars.Start(), that will show while those routines are executing? I need the equivalent of DoEvents.
Was thinking Coroutines might be the way to go, but I think that puts it on a different thread, and I won't be able to update the values.
Any suggestions?
So now I've tested coroutines as well. No good.
What I'm really looking for is the means to load a level, and have all of the Start routines completed, but show their progress. Not finding it.
Coroutines will work. Loading a scene is it's own thing, so you will either need a separate progress for both the scene and placement of objects or fake it, by making the progress bar only fill to 90% or something for the scene and then use the last 10% for the placements.
Can't say why the Canvas isn't updating, you haven't provided any details or code. Try delaying the Starts by a frame so the UI has a chance to initialize itself first.
@jessespike Not sure what code I'd need to provide, but this is what I'm doing:
// Use this for initialization
void Start () {
StartCoroutine(CreatePeople());
}
IEnumerator CreatePeople()
{
// Wait for GUI to draw
yield return new WaitForEndOfFrame();
// Rest of routine, including updating the Loading Screen, which still doesn't display
}
Coroutines didn't work. It still does the same thing, which is a long pause and then the game starts all at once, with the cars and people already created and distributed.
I've tried WaitForEndOfFrame (which is supposed to allow loading to finish and GUI to draw), and WaitFor Seconds(1), which just made it take longer, but still not give me a loading screen.
I've also tried putting it in the Update function, with code to disable it after it runs once. That showed the GUI for a quick flash at the end of the long wait, but did not update it, and it wreaked havoc on my other routines that rely on the people and cars being there.
Also, to be clear, I'm not concerned about displaying during the scene loading, since the scene is pretty lightweight and loads quickly. I'm concerned with showing a percentagebar on how long these routines take during the Start function, but the loop does not allow the GUI to update/draw/refresh.
Final thought (unless someone comes up with something). If I can't get it to work as is, I $$anonymous$$AY be able to move these routines into the Loading GUI itself, and have them called from the GUI. I don't like the organization of that, preferring to have my CARS GameObject call it's own CreateCars script, but if that's not going to update the GUI, then maybe I do need to run this in the GUI.
Your answer
Follow this Question
Related Questions
Problem with coroutine. 2 Answers
How to instantly restart a coroutine? 1 Answer
Staggered Animations - Do I use Pre-fabs ? 1 Answer
SpeedBoost won't reset : Problem with either WaitForSeconds or Coroutine (Solved) 2 Answers
Coroutine? 4 Answers