1
\$\begingroup\$

Is there a way to load a heavy built scene behind a loading screen in unity to not make the game look like stuck loading the scene rather show the player some loading bar that would help the player think some background process is happening. any sites or vidoes that describe about this would be a great help! Thanks!

\$\endgroup\$
4
  • \$\begingroup\$ showing a short animation in a simplified scene while everything else is loading in the background should be pretty simple. Basing the animation off the progress is a bit trickier but doable. \$\endgroup\$ Aug 13, 2019 at 8:31
  • \$\begingroup\$ how would you do it can you elaborate please! \$\endgroup\$
    – zsshan07
    Aug 13, 2019 at 9:02
  • \$\begingroup\$ Presumably you consulted the documentation on SceneManager.LoadSceneAsync ? Have you run into any specific difficulty putting the documented examples or many tutorials on this topic into practice? \$\endgroup\$
    – DMGregory
    Aug 13, 2019 at 11:10
  • \$\begingroup\$ @DMGregory i did but the documentation did not completely give a picture of what i wanted to know like there s another way of loading with loadmode.additive to be less precise but i wanted some examples and opinions on how is it possible on simple terms...your links did the work!thanks \$\endgroup\$
    – zsshan07
    Aug 13, 2019 at 11:23

1 Answer 1

1
\$\begingroup\$

Yes, with SceneManagement.LoadSceneAsync(newScene).

This method loads the new scene in a background task while the current scene keeps running. You can check the progress by keeping the AsyncOperation object returned by that method and checking its property .progress. If you do that in an Update method of the loader-scene, you can use its value to update a progress bar or similar.

Example script which represents the loading progress by updating a percent value on a UI text:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;

 public class Preloader: MonoBehavior {

      public Text progressText; // <-- Assign a text label on a canvas to this using the inspector

      private AsyncOperation loadOperation;

      void Start() {          
           // start loading the scene "game"
           loadOperation = SceneManagement.LoadSceneAsync("game");
      }

      void Update() {
          // update the text on the UI
          progressText.text = Mathf.floor(loadOperation.progress * 100f).ToString() + "%";
      }
 }
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .