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.
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)
+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.
+Aaron Murray Thanks alot lad you just saved my life
THIS DOESN'T REQUIRE UNITY PRO ANYMORE BY THE WAY
ChunkyChopsable Yeah ! With Unity 5 Personal Edition You can do this !
Was about to say
Thank u
Thank you for the excellent video!
awesome video,
keep going bro
Awesome, great help :D
thank you , very helpfull.
Thanks! It works!
My scene doesn't load. It's just black and pink textures.. What to do? (I have a big scene btw)
i did everything right but it keeps freezing at points mostly start and end (not just in editor)!!
what it stop in 90%?
+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
how use it in a button?
Replace if(input.....)
by
if(GUI.Button(new Rect(//put your button options), buttonName);
thanks you !! :) :)
^^
Nassim Allali can you give me an example in new UI style, in my case i created a button in a canvas
Willy ahmad syafiq sorry i don't use the UI style :p i only use the OnGUI Fonction :p
What could I do to make something similar with unity free?
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..
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?
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.
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 :)
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?
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?)
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.
+Chubzdoomer Can you post a link for how to do this ? Thank you...
Sorry, but is it normal way to creating loading screen ?
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?
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.
my async.progress is always 0. cant seem to see the problem
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.
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!
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".
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
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
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.
Remove "uhhhhh" from your vocabulary.
Was wondering why a tutorial of this nature was over 30 minutes long. Explaining variable names like 'levelToLoad' tsk.
I need a game over script. I need the over to show up after the player dies. Can you inbox me one ?
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.
I was going insane seeing that "yield return null" without the ; at the end.
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?
COOLGAMETUBE of course it will work!
Great tutorial, thank you very much for sharing :)
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?
***** 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
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.
Are you using unity Pro? Async feature will work only on Unity pro.
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
UI tutorial?
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
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.
Thank you Bro Please Create More Video
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 :)
StartCoroutine(DisplayLoadingScreen(levelToLoad));
add a guiText object to the rig...
Thank you for the explanation !
CRACCCCCCK!!! U save me!! THANKS A LOT!
how i can start the loading Screen with a button?
help me,please.
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.
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?
make multiple load screens
Its a prefab, just drop it in each lvl.
here all right thanks friend
17 minutes intro...
It is great!
THX video ^^
Thank you!
Start 16:50
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
***** are you guys already solved this? i need help :(
***** 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
Keannu Zeigfeld Atilano put the loading progress text on the Update function ^_^
RetseL this one? text.guiText.text = "Loading Progress " + loadProgress + "%"; still not works :( can i see your code please..
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..