How To Use Unity Addressables For Beginners Part 4 (Scene Loading)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on everybody this is denmark and welcome back to my channel so in today's video i'm going to continue the unity addressable tutorials but this time we're going to be looking at loading and unloading scenes this is going to be used and actually created by using the addressables api we're also going to be looking at how we can add those scenes to the different groups that we already have and also how we can go ahead and make changes to a scene so that we can actually send those changes to the cloud so let's jump into unity and start working on it alright guys so the first thing that i'm going to do is i'm going to go ahead and clone the playground scene which is the one that i created previously and this one we can just leave it as playground and i'm going to clone it twice one of them is going to be level one and think of it as each level it's going to be the assets that we see here and then the playground just going to have the basically the ground and also the player controller and the lighting and additional items that are going to be reused for level one and level two so on this scene what we'll do is i don't really want to have the environment the only thing that i'm gonna have in here and i'm gonna go ahead and unpack it it's going to be the ground so i'll grab the primitive which contains the ground and i will remove the environment this one we can just rename to a gram and then that way you know when the player loads it's going to load in the ground and then we can load level one and level two as needed and i can also remove that cylinder there so now if we go back to level one this one has everything else and i don't need everything else we can just keep the environment i'm just gonna go ahead and remove that and then i'll go ahead and unpack this one completely as well and then i'll also remove the primitive which is going to be the ground remember what we want to load is just the environment and then i'll do the same thing on level two we'll go ahead and remove the lighting we'll remove every single other component and then i'll also unpack the level 2 here and there'll be one thing that i need to do that i'm going to just so that it looks different right we don't want the same level multiple times so one of the things that we can do is we can clone perhaps we can clone the tunnel here and then maybe we can make it a little bit bigger maybe the tunnel goes all the way back here and the way the player can go through multiple tunnels and then i'll also clone this wall here climb it one more time and then maybe this one i'll just clone it rotate it and then this box here i'll just move it up and that way it looks different right we want to make sure that we create a different level so that our players don't get bored but this is for prototyping so we don't need to spend a lot of time okay so now what i'm going to do is i'm going to go back to my playground scene it's going to be your main scene everything should work just like it worked before so if i were to hit play you're going to see that the my armature the player controller is going to load the also the unity logo should load and also the music should low so everything in here should work just like it did you know it did before so what we're going to do is we want to low level 1 level 2 through addressable so i'm going to go ahead and add that and also at level two and then remember these keys because these are going to be very important aspect of loading the asynchronous scenes that we're going to need okay so now that we have that we're going to need to do some coding to be able to load those dynamically and i also need to have a couple buttons on the scene so that we can load those so what i'll do i'll just go ahead and clone the bounce first so we can work on that ui piece this is going to be pretty simple we just do a bun here that is going to lower level one and then another button that is going to low level two and this one we can just say low first level and then i'll do the same thing on the other one i'll just call it low second level let's go ahead and rename that and make sure that i have my casing correctly here capital l and then what i'll do is also change the text so that we know that we're loading so it's going to be load level one and then i'll do the same thing on this other one here we'll just go ahead and call it level two and then we'll go back through and then buy into a method that we need to that we need to create so we're gonna go into addressable manager which again we created on the previous video and then what i'll do here and this is going to be for level i'll just call this one level loading and in here i'm going to create two different variables one of them is going to be ball clear previews we're going to say they're called scenes i call it levels but i'll just call this one scene and then i'll just say false so by default we're not going to clear the current scene because we haven't really loaded and then the other thing that i'll do is i'll just do see instance and i'm going to keep track of the previous scene that way if we loaded a scene we want to make sure that we clear the next time so we don't have you know a memory leak so i'll just do previews loaded scene and then this is going to be it's going to be a null value and now we need to create a new method it's going to say public void and then it's going to be low addressable and then we can just say addressable key this is going to be the key that i show you on their groups so we'll pass that through a canvas but an event and then basically that will determine what needs to load and then the first thing that i'm going to do is i'm going to say okay do i need to clear the previous scene but if i need to clear it so it's going to be true so what i'll do is i'll go ahead and call the addressable and it's going to be low scene because that way if we need to clear it we need to unload the previous scene so that we don't have you know memory leak like i was saying and then we'll just do this one is going to be previous loaded scene but we need to get a call back right we want to know you know what if that scene got unloaded so that we can set this value appropriately and also we can determine if we can load the next scene so what i'll do here i'll just say plus symbol and then it's going to be my async handle and i'll just do a lambda here and we just do a semicolon so what's going to happen is i want to make sure that you do the async method and not the non-async method so what i'm going to happen is i need to clear the previous scene so i'm just going to set this one to true and then the next thing that i need to do to is i need to make sure that i initialize the value here and this is something that unity did in their examples i think it's good not to keep it as null so we can just say new scene instance and then we can just log some information that we have and then what i'll do here is on the in the case that we don't have to clear the previous scene i'm just going to load the scene right so i'm going to go ahead and just change this method here and it's going to be load scene async and then this is going to ask for the addressable key so we need the addressable key it's also going to ask for the losing mode and i don't need this big namespace i'm just going to bring the name space so that it's shorter and then i'm going to use the additive and then the other thing i want to do is we also need to check on the completion right we're going to do the exact same thing that we did above it i'm going to get the sync handle and if you want to do a new method for this you know you can do that as well i just want to keep it short and then i'll just do the clear previous scene equal to true so sorry in this case i need to set it to false because i'm you know there's no need to clear it because i'm already unloading it but in this case i need to set it to true so if we click the button again i need to make sure that it gets clear and then what i'll do here on the previous loaded scene we need to basically grab the sync handle and i'll grab the result object which is going to be the scene instance and then we can just go ahead and copy this so that we can print some information so i can say load it scene and it's going to be the scene that they got loaded so it's pretty much everything that we need to do in there what's going to happen is when i click on it we're going to pass the the addressable key value it's going to determine do i need to clear the previous scene if i don't i just load it next time around it's going to say okay i do need to clear it and then i'll load a new one and we already have a method here because i reuse that from the low level so let's go ahead and add a new one and then i'll do the same thing here remove that one add a new one and then what we need to do on both of these ones is i'm going to drag and drop the addressable manager drag and drop the addressable manager here and then this one is going to crawl into the load addressable level and remember this is the key that we need so it's going to go ahead and copy that and you can rename that if you want that to be shorter i think i'm just going to use the long name and then i'll do the same thing on this one let's go ahead and look for the low addressable level and this one is going to be level one okay so we have our main you know our main scene which is the playground scene now if i wanted to reload the level everything should work just like it did before if i want to load level one you can see that level one got loaded let me go ahead and low level two and now you can see that and it also says in here level one got basically removed actually level two got removed and then level two got reloaded and then yeah so the same thing on those so if i wanted to run here you're gonna see that this one is the one that we created with more tunnels so i can go through here through my tunnels this is level two well if i wanted to low level one we can lower level one and now everything you know everything loads correctly so what i'm going to do now is i'm going to go ahead and create a new bill so that we have because we add a new implementation we can't really just update the content in the server so what i'll do is i'll go here and then clean the bill i'm going to clean everything and then i'm going to do a brand new build because we have brand new implementation at it okay so it looks like that got loaded i'm also going to go ahead and create a new bill that we're going to need into the build folder okay so looks that we have now a new bill so what i'm going to do as well is we need to go ahead and pull the new content data that got generated and then we have this new content okay so now what i'm doing is i already have my basically a space in digitalocean so i'm going to go ahead and remove everything that i have before and yep let's go ahead and remove all five items and then i'll drag and drop everything that we just generated drag it and drop it into my folder there and then just go ahead and set it to public so now that we have everything in the cloud i should be able to run my bill i'll just wait until the upload process finishes we can go back into my build and you can see that the level got loaded and this is a new implementation right this is the one that doesn't have the low the level data let's go ahead and go into level one and we have level one at it and go ahead and go here i think level two was cooler because i have multiple columns and let me go ahead and place myself somewhere here let's go ahead and low level two and level two has the tunnels right so i can go here i also have multiple walls we have multiple you know the multiple tunnels and then everything works so that's everything that i wanted to show you today as far as like how to low levels dynamically obviously the power comes in actually making changes to a level so if i wanted to make a change here to this level and let's say that your designer comes in and they say you know what i want to add a new model you can drop in the new model and then make those changes and then just create a new bill but in this case it's going to be an update to a previous bill and then all you really need to do is just drop those files in here reopen the the bill and everything should reflect and it changes so that's everything that i wanted to show you today guys if you guys have any questions please let me know thank you
Info
Channel: Dilmer Valecillos
Views: 20,607
Rating: undefined out of 5
Keywords: unity addressable scene loading, unity addressables scene, Unity Addressables Remote, Remote, Assets, Unity Addressables Hosting, remote load path, remote build path, unity addressables remote hosting, addressable assets update remote assets, addressable assets aws update, assetbundles unity, asset bundle, unity tutorial, assetbundle, unity asset bundle, assetbundles, memory leak, addressable asset tutorial, unity3d addressable assets, addressables, unity instantiate, async, load
Id: BXdwcSLWXK4
Channel Id: undefined
Length: 11min 12sec (672 seconds)
Published: Fri Jul 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.