Scripting a Loading screen in Unity

Поділитися
Вставка
  • Опубліковано 28 вер 2024
  • In this tutorial I'll be going over how to create a loading screen for your game. Loading screens have a useful purpose of showing players that the game has not crashed or frozen and is just loading a new scene and assets. They are also a requirement for most platforms.
    This implementation of a loading screen in Unity will require a Unity Pro license because of the use of the Application.LoadLevelAsync function.
    Coroutines are also covered in this tutorial and if you are still unsure of how they work, I highly recommend reading Unity's article on coroutines.

КОМЕНТАРІ • 94

  • @amurray04
    @amurray04 9 років тому +1

    As people noted, this works great with Unity 5.x, however one quick change, due to the GameObject property 'guiText' being deprecated.
    The 2 places in the code that read:
    text.guiText.text = "Loading Progress " + loadProgress + "%";
    Should now read:
    text.GetComponent().text = "Loading Progress " + loadProgress + "%";
    Otherwise the rest of the code remains the same. Thanks for creating this great tutorial, I am pretty new with Unity (and CSharp in general), these tutorials help greatly during my learning process)

    • @horizonman34
      @horizonman34 9 років тому

      +Aaron Murray Yep, figured that out myself... They change the API in the most annoying ways, but I guess if it's deprecated it's deprecated and needs to be fixed.

    • @SlevinFowl
      @SlevinFowl 8 років тому

      +Aaron Murray Thanks alot lad you just saved my life

  • @ChunkyChopsable
    @ChunkyChopsable 9 років тому +38

    THIS DOESN'T REQUIRE UNITY PRO ANYMORE BY THE WAY

  • @SimonPrefontaineGames
    @SimonPrefontaineGames 10 років тому

    Thank you for the excellent video!

  • @AlltimeOnlineGyaan
    @AlltimeOnlineGyaan 9 років тому

    awesome video,
    keep going bro

  • @Psycho8Everything
    @Psycho8Everything 10 років тому

    Awesome, great help :D

  • @Jazzy7664
    @Jazzy7664 8 років тому

    thank you , very helpfull.

  • @royalking1997
    @royalking1997 10 років тому

    Thanks! It works!

  • @ineedshark
    @ineedshark 8 років тому

    My scene doesn't load. It's just black and pink textures.. What to do? (I have a big scene btw)

  • @lewiskerley8555
    @lewiskerley8555 8 років тому

    i did everything right but it keeps freezing at points mostly start and end (not just in editor)!!

  • @PehBlue
    @PehBlue 8 років тому +1

    what it stop in 90%?

    • @PehBlue
      @PehBlue 8 років тому +1

      +Pedro Nascimento and LoadLevelAsync just jump form 0% to 90%, and them stop. because there are some stuff doing in background. after this the scene is load. so it appear not work as suppose to. help please

  • @carlosjurado2012
    @carlosjurado2012 9 років тому

    how use it in a button?

    • @medvfx3370
      @medvfx3370 9 років тому

      Replace if(input.....)
      by
      if(GUI.Button(new Rect(//put your button options), buttonName);

    • @carlosjurado2012
      @carlosjurado2012 9 років тому

      thanks you !! :) :)

    • @medvfx3370
      @medvfx3370 9 років тому

      ^^

    • @d3vzvanezzia
      @d3vzvanezzia 9 років тому

      Nassim Allali can you give me an example in new UI style, in my case i created a button in a canvas

    • @medvfx3370
      @medvfx3370 9 років тому

      Willy ahmad syafiq sorry i don't use the UI style :p i only use the OnGUI Fonction :p

  • @RupluttajaGames
    @RupluttajaGames 10 років тому

    What could I do to make something similar with unity free?

    • @Nekomatix
      @Nekomatix 10 років тому

      See that's the point of half of the tutorials posted on this channel... make you want to buy unity pro. Simple and efficient. As for your question... Google is your friend..

    • @RockYourTeeth
      @RockYourTeeth 10 років тому +2

      Noodle Slayer Wouldn't it be frustrating if you had paid for the pro version and then couldn't find any good tutorials for those features?

    • @Nekomatix
      @Nekomatix 10 років тому +4

      Nick Hester Well that is true, but so far I'm pretty content with a Free version. And I do not have around 500$ to spare just so I can tinker around with games I'll probably never finish.
      Also I think if you've actually paid for a pro version you should be skilled enough to figure it all out by yourself.

    • @etaxi341
      @etaxi341 10 років тому

      I do it like this: I make the loadingscreen popup before i load the scene. After you see the loadingscreen I load the scene. You cant animate the Loadingscreen with my method but you can have one :)

    • @RockYourTeeth
      @RockYourTeeth 10 років тому +1

      Noodle Slayer that doesn't really make sense. What does your level of skill have anything to do with magically knowing how to do something with no one teaching you?

  • @mimiboo
    @mimiboo 8 років тому +1

    I've got an 4 errors
    1- Assets/Scripts/LoadingScreen.cs(41,22): error CS0619: `UnityEngine.GameObject.guiText' is obsolete: `Property guiText has been deprecated. Use GetComponent() instead. (UnityUpgradable)'
    2- Assets/Scripts/LoadingScreen.cs(41,30): error CS1061: Type `UnityEngine.Component' does not contain a definition for `text' and no extension method `text' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)
    3- Assets/Scripts/LoadingScreen.cs(47,30): error CS0619: `UnityEngine.GameObject.guiText' is obsolete: `Property guiText has been deprecated. Use GetComponent() instead. (UnityUpgradable)'
    4-Assets/Scripts/LoadingScreen.cs(47,38): error CS1061: Type `UnityEngine.Component' does not contain a definition for `text' and no extension method `text' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

  • @Chubzdoomer
    @Chubzdoomer 9 років тому +2

    This is insanely easy with Unity 5's new GUI system, especially since you can just tie the _loadProgress_ variable to a slider. I'm glad they dumped that crappy old GUI system for something far more intuitive and flexible.

    • @fdyonur3
      @fdyonur3 8 років тому +1

      +Chubzdoomer Can you post a link for how to do this ? Thank you...

  • @HieuNguyen-kt9ks
    @HieuNguyen-kt9ks 10 років тому +1

    Sorry, but is it normal way to creating loading screen ?

  • @robinlinh
    @robinlinh 8 років тому +2

    I have a question: what process is considered "loading"? In here it showed that loading mean it load the game object we have in our scene. But for example I have a script to generate dungeon, if I attach it to a game object and put the generate dungeon on the Awake() method does it run in the "loading" process? And if no then how do I include that script to the loading process?

    • @konter6730
      @konter6730 7 років тому

      For procedural generation I don't see the need for loading screen of this type, you just load and then while your script is generating you add loading screen. And ofcourse you need to calculate progress on your own etc.

  • @YugiMango
    @YugiMango 9 років тому +2

    my async.progress is always 0. cant seem to see the problem

  • @churi24
    @churi24 6 років тому

    Application.LoadLevelAsync is deprecated right now. You have to use SceneManager.LoadSceneAsync If the scene to load is big, I dont know why, but the program freeze. It's like the loadsceneasync is running on the main thread, even if you write the method inside a coroutine.

  • @coolfunkDJ
    @coolfunkDJ 9 років тому

    Thank you so very much with this :) I wasn't aware of how to do this so my game would just freeze for 10 seconds before loading into the level ahaha! I love the way you teach, +1 Subscriber!

  • @hawksandwich4742
    @hawksandwich4742 8 років тому

    Hi :3 For me, when I start the coroutine the entire game freezes, waits a bit, then loads the next scene. I've always had trouble with coroutines and I'm starting to think it's my Unity, because I did everything you did here and it's just not seeming to load anything in the "background".

  • @onesketchyguy6050
    @onesketchyguy6050 7 років тому

    at the top do
    using unityengine.scenemanger;
    and instead of application.loadlevelasync do LevelManager.LoadSceneAsync;
    AND instead of text.guiText.text do text.GetComponent().text
    This will work with unity 5

  • @chankygames581
    @chankygames581 9 років тому

    Incrementally load your scenes in Unity3D (free) with loading bar!
    Using Unity 4.6 new GUI system or OnGUI! (will also work with NGUI)
    www.assetstore.unity3d.com/en/#!/content/28035

  • @MrSmoczek1992
    @MrSmoczek1992 9 років тому

    This is very good tutorial it helped me a lot thank you for putting on here. However I am really bad at coding but I have to prepare something for my dissertation project to test theory. And I want it to ask if you could show it or explain it how could I change the code to control how long the loading bar will go for like 30 second or 45 second and show the progress with % if you know what I mean. like 10% after 5 second then 15 second and 56% and so on. Is it possible ? if yes would be possible of you showing how please ? Thank you.

  • @josephknightcom
    @josephknightcom 8 років тому +4

    Remove "uhhhhh" from your vocabulary.

    • @darkhummy
      @darkhummy 8 років тому +1

      Was wondering why a tutorial of this nature was over 30 minutes long. Explaining variable names like 'levelToLoad' tsk.

  • @authenticreign6155
    @authenticreign6155 9 років тому

    I need a game over script. I need the over to show up after the player dies. Can you inbox me one ?

  • @walkingdadjokes6099
    @walkingdadjokes6099 8 років тому

    Thanks for sharing this. I saw this in some written examples but it's so much easier when someone explains it as they are doing it.

  • @SilverAura
    @SilverAura 8 років тому

    I was going insane seeing that "yield return null" without the ; at the end.

  • @SimonNitzsche
    @SimonNitzsche 9 років тому

    In a Video i heared, that Unity supports all Pro Only Scrippting functions from Unity 4 in the free Version.
    Sooo...
    Will it work in Unity 5 Personal Edition?

    • @R3DCODE
      @R3DCODE 9 років тому

      COOLGAMETUBE of course it will work!

  • @LandRGuy
    @LandRGuy 9 років тому

    Great tutorial, thank you very much for sharing :)

  • @True_Beef
    @True_Beef 9 років тому

    Great tutorial! However, (I believe this is a problem with my logic) Whenever i Asynchronously load one of my levels, it loads it "Starts" it over and over again. To explain what this would look like, imagine you have an object that moves to the right on scene start. It would move right, then teleport back to where it started again, then move right, effectively restarting the scene a good 5 or 6 times before stopping.
    If you understand what im talking about, do you know how to fix it?

    • @loekTheDreamer
      @loekTheDreamer 9 років тому

      ***** it sounds like your either loading the scene at the wrong time or loading the incorrect scene. check that the scene your editing in is the scene that is added in the build menu. i sometimes forget and then my build is actually looking for the scene that i have net saved my changes to

  • @LionRoid
    @LionRoid 9 років тому

    Hi. Thanks gor your video. But when used these codes, I saw these error:Asynchronous Background loading is only supported in Unity Pro.
    Please use Application.LoadLevel or Application.LoadLevelAdditive instead.
    UnityEngine.Application:LoadLevelAsync(String)
    c__Iterator0:MoveNext() (at Assets/Scripts/LoadingScreen.cs:37)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    LoadingScreen:Update() (at Assets/Scripts/LoadingScreen.cs:23)
    please help me.

    • @steamrolleast4318
      @steamrolleast4318 9 років тому

      Are you using unity Pro? Async feature will work only on Unity pro.

    • @chankygames581
      @chankygames581 9 років тому

      Incrementally load your scenes in Unity3D (free) with loading bar!
      Using Unity 4.6 new GUI system or OnGUI! (will also work with NGUI)
      www.assetstore.unity3d.com/en/#!/content/28035

  • @UnityJab
    @UnityJab 9 років тому +2

    UI tutorial?

  • @YugiMango
    @YugiMango 8 років тому

    why cant i add like a 3d object to the loading screen? it doesnt show up on it, only on the menu. it only allows me to show guitextures etc

    • @darkshadowsx5949
      @darkshadowsx5949 8 років тому

      not sure what your doing wrong...
      i've had 3d gears moving on a gui before... needs to be lit by a light source but that's it.

  • @sarkarrawf370
    @sarkarrawf370 8 років тому

    Thank you Bro Please Create More Video

  • @konkgames
    @konkgames 10 років тому

    Hey! Just having a small problem. I get the error:
    There is no 'GUIText' attached to the "LoadingScreen" game object, but a script is trying to access it.
    I know this is a little out of date, but I was wondering if you wouldn't mind helping me fix that? Thanks :)

    • @konkgames
      @konkgames 10 років тому

      StartCoroutine(DisplayLoadingScreen(levelToLoad));

    • @shukfahid
      @shukfahid 9 років тому

      add a guiText object to the rig...

  • @villedesceaux6207
    @villedesceaux6207 10 років тому

    Thank you for the explanation !

  • @sharomt4192
    @sharomt4192 9 років тому

    CRACCCCCCK!!! U save me!! THANKS A LOT!

  • @gamepietro1991
    @gamepietro1991 9 років тому

    how i can start the loading Screen with a button?
    help me,please.

    • @FireGameplayer100
      @FireGameplayer100 9 років тому

      pietro gameita Create with a public function ; then call that public funcion with the OnClick event on the UI buttun, the script that contains the public function need to be on a gameObject , would be a empty game object.

  • @CadenBurleson
    @CadenBurleson 10 років тому

    What about if I have multiple levels, how am I supposed to load the loading level, and then update the async level to be the next one?

    • @jimmytlewis
      @jimmytlewis 10 років тому

      make multiple load screens

    • @shukfahid
      @shukfahid 9 років тому

      Its a prefab, just drop it in each lvl.

  • @rafaelyahu
    @rafaelyahu 8 років тому

    here all right thanks friend

  • @vasyapupkin9338
    @vasyapupkin9338 6 років тому

    17 minutes intro...

  • @greengreyredggr2964
    @greengreyredggr2964 10 років тому

    It is great!

  • @ZergHUN
    @ZergHUN 10 років тому

    THX video ^^

  • @bscblack100
    @bscblack100 8 років тому

    Thank you!

  • @vasyapupkin9338
    @vasyapupkin9338 6 років тому

    Start 16:50

  • @keannuzeigfeldatilano2331
    @keannuzeigfeldatilano2331 9 років тому

    Hi i am currently making a game. your script works but what happens here is whenever i hit space it will only show the "Load progress 0%" and it will not change same goes to the loadingBar .after 5 seconds it loads my next level.Please Help

    • @d3vzvanezzia
      @d3vzvanezzia 9 років тому

      ***** are you guys already solved this? i need help :(

    • @d3vzvanezzia
      @d3vzvanezzia 9 років тому

      ***** can i see your source code? it still does not works, the percentage still 0% and progress bar does not appear,even i testing in my android device

    • @boblester122
      @boblester122 9 років тому

      Keannu Zeigfeld Atilano put the loading progress text on the Update function ^_^

    • @d3vzvanezzia
      @d3vzvanezzia 9 років тому

      RetseL this one? text.guiText.text = "Loading Progress " + loadProgress + "%"; still not works :( can i see your code please..

    • @boblester122
      @boblester122 9 років тому

      Willy ahmad syafiq yes, i did this on unity 5's new UI ... i thought it would work on you because i also got the same problem when i put it inside the coroutine. i'll try to make a tutorial for new UI version, but for now, let me see your code instead..