Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to make a progress bar for a loading scene?

Discussion in 'Editor & General Support' started by squffed, Oct 21, 2022.

  1. squffed

    squffed

    Joined:
    Mar 19, 2022
    Posts:
    4
    Hi there,

    Currently working on a procedurally generated island survival game. In the Game scene, it starts by spawning all the necessary objects onto the terrain (tree objects and grass). What I would like is when the player goes into the game for this progress to be seen.

    I have setup an Editor GUI which shows this progress as a EditorUtility.DisplayProgressBar object.

    What I want to ask is how do I talk from the loading scene to the previous scene (i.e. a loading scene) to update a progress bar within the game - however trying this with my attempts I noticed the game actually freezes when the objects are being loaded. The Progress Bar object seems to be independent of the game and shows this progress fine.

    Maybe it's possible to get a Build version of the Editor Utility? Let me know and thank you for viewing this.
     
  2. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    61
    Hi @squffed, sounds like a fun game. One way to create an in-game progress bar is to use an image with "Image Type" set to "Filled" for your progress bar as shown in this video. Then adjust the "Fill Amount" of the image dynamically with a script. I'm not sure what you mean by "talk from loading scene to the previous scene", but maybe you mean you have some state that needs to persist across scenes. I usually use "Don'tDestroyOnLoad" as a convenient way to make objects persist across scenes.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,717
    In addition to what @dynamicbutter suggests above, you would need to make your generation into some kind of coroutine that yields regularly. here's why:

    Unity will lock up 100% of the time EVERY millisecond your scripting code is running.

    Nothing will render, no input will be processed, no Debug.Log() will come out, no GameObjects or transforms will appear to update.

    Absolutely NOTHING will happen... until your code either:

    - returns from whatever function it is running

    - yields from whatever coroutine it is running

    As long as your code is looping, Unity isn't going to do even a single frame of change. Nothing.

    No exceptions.

    "Yield early, yield often, yield like your game depends on it... it does!" - Kurt Dekker