How To Use Unity ADDRESSABLES With CLOUD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Unity addressables give you more control over how and when everything is loaded into the game which will help you to save gigabytes of your RAM it is especially useful for loading large words like in games Assassin's Creed the viter or Skyrim it will also help you to improve the performance on mobile devices and the most useful feature is connecting it with Cloud that will allow you to push changes to the cloud and the players of your game can keep the same build and it is going to out automatically update to my game I have just added this large word and it is not actually spawned in the game yet it is just reference in a script that will automatically spawn it when I press W and I have also made a build of the game as I play the game you can see that it is already taking a lot of R even though we are just an empty scene and this is because the whole world is already loaded in the background so this is what adjustables will help us to solve so when we don't need the object it is not going to be loaded in the background first we'll need to download the address package so go to your package manager go to Unity registry packages search for addressables and click install once we have that we can create new script and put it to some empty object in our scene which will be our addressable sler we will implement the unity engine. addressable assets namespace and there is pretty much just one the most common function that we will be using which is the load assets async which we can get using the address SE class and we want to be using the async one which is short for asynchronous which means that it is not blocking the main threet so the game can still continue even when we are loading some of these assets but before we can start loading some objects we actually needs to mark them as addressables so I will go back to Unity open window asset management addressables and we will just care about the groups and profiles windows for now so going to the groups window first it will just ask you to create the addressable settings so just do that it is going to generate some files where we have a bunch of settings we can see these settings in the addressable assets data folder that we'll need to modify later in the addressables groups you can see that we have a default local group to which we will be adding all of our assets that we want to load using addressables so I will select my terrain demo for which I have made a prefab and just simply drag it to the group and now you can see that when I select the prefab in the project we have ticked that it is a addressable asset and it is also showing us the path so if you want to make your asset addressable you can just drag it in or you can just stick addressable and you can also do the same thing for the folders so you can see that it just appeared here now as this asset is marked as addressable we can easily use it in the script so there are three ways that you can reference these objects the first one the most ugliest one in my opinion is to use the addressable path so we can just copy this string go to the script say addressables load asset async which type of asset is it it is game object and then to the parenthesis we'll need to specify the location so just paste in the path and that's how we manually load asset into our game right now we can't really do anything with it so we'll need to create reference for the async operation handle which will also be storing the final result game object so we will need to add using commity engine resource management. async operations so I have created async operation handle of type game object that's important that you actually specify of which type the handle it is and now we can do some interesting stuff with it such as we can get the result so I can just type handle. result which in this case would give us the game object we can't instantiate the object right away after we load it because we are not sure if the loading was done because it can take some time and because it is a synchronous operation it is not going to block the main thread so the code will just go so from the handle we can access the completed which we can then assign to some function so to the completed event I have subscribed new function that I have just created it is just a void that is taking in the async operation handle of the same type of the handle that we have just created and in the function I'm also doing some additional stuff which is just checking for the status if the async operation has succeeded if it did then we can just instantiate the object which I'm taking from the handle that result so if you would want to do something with Sprites textures you can always access the result using that result so using this line we are just telling it that after it finishes loading we just want to spawn some object so once I press W it should do that so I'm pressing w Wait for some time and we can see that indeed it loaded the whole world once I started the loading it takes a bit more time but the benefit is that once you load the game it is not going to take so much time because the objects are not already loaded what if you don't like working with strings like me we can just create a variable that will be storing the asset reference to the asset that we want to load and instead of calling the function on the addressables class we'll just call it on the asset reference itself and then in the parenthesis we are not specifying any parameters but this way what if the user specifies let's say audio clip as the environment reference then it will give us an error because here the type is specified as game object so the best way to do it is to specify that the asset reference should be game object so this here is the safest way to load your addressables and back in unity we can't forget to set the environment reference so just open your addresses group and drag it in or we can also just drag it by the prefab from your project or if there is an object that you don't have yet in the addressables group window you can just drag it straight away and it is going to work if the type is the game object yep and we can see the environment is loaded correctly once more and if you are just instant shating some objects you can use the instant shate acing function which will make your code even cleaner so we can do the same stuff just with one line of code soal the instant shade acing function on the asset reference and to the parenthesis you can also specify the position rotation parent and so on Yep this still works the same and if you want to add your own asset reference let's say for audio clip you may start to search for it so asset reference but you can see that there is no audio clip in here so the way that we do that is to create our own class we can just name it asset reference audio clip make sure that it is system that's utilizable so we can see it in the inspector and this class is going to derive from asset reference T where we actually specify the type that we want this asset reference to be and then we just need a Constructor for it so now I can make a variable of type asset reference audio clip and when I try setting the game object to it it doesn't work because we need to input some audio clip so the first way to load your addressa asset is using the string the second way is to load them using the asset reference and the thir one is to load them using labels so you create one just like that pretty simple and these labels can be pretty useful for example if you want to load an entire folder of some stuff so I have added folder into the addressable groups and if you would try dragging it just into normal ass set reference with no specified type it would work but once you would play the game it would do nothing so the way to load entire folders is to just Mark the entire folder with some label so you can set them using this dropdown you can can also manage labels to add your own and when I set for example to the default label and I open the folder all of the objects inside it are also marked in the default label and in the inspector I can then easily specify the label just by selecting it and in the script if you are loading multiple assets because you are using the label you also want to make sure that all of the assets are of the same type because then as we are loading it we are using the load assets asnc function we need to specify the type so it can be anything you want and then into the parameters we are inputting the label and then I just created an anonymous function that takes in the game object as a parameter and then it just adds some position to it so if you are loading the assets using the completed event which we have here on the handle you actually don't have to be creating a separate function for it you can just create Anonymous method like this so that's how we can load addressable assets using a string asset reference and asset label now we will get to the most useful feature in my opinion which is to use addressable with Cloud so that you can easily push changes to the cloud and players of your game won't even need to download new build to connect Unity cloud with our Unity project we need to make sure that the project is linked to a Unity ID so if it is not you can go to edit project settings services and here if you see all of this info it means that it is connected if it is not then you can just hit a link with unity ID then we'll jump to our browser and search for Unity Cloud we'll open this page cloud. unity.com you can just sign in once you are signed in you can take a look into your projects and select the project for which you want to use the cloud then we can just scroll down and if you wouldn't have the cloud content delivery active which is the package that you'll use to make the addressables work with cloud and don't worry the first 50 GB are for free which is quite a lot so you would just scroll down find the cloud content delivery and hit launch then it will ask you to input your payment information but as I said the first 50 GB are for free which you can also see here once you have launched the cloud content delivery for your project you can go to buckets and create new bucket and just follow the onscreen instructions once you have the bucket created as you can see I named my just windows under it you will also be able to see all of the entries as for the files that we have added into the bucket and you can also upload new content then we will go to the addressable remote path URLs which will just allow us to get the URL of the server and access the data so for now we'll copy the latest batch which is just pointing to the latest release we'll go back to Unity and we'll need to open new window so we go to window Asset Management addressables and we'll open the profiles window here we can set up where we want to save and load all of the files from addressables so we'll need to edit the remote path so I will select custom and to the load path we can paste the path of our server so Unity knows from where we should download all of the files and we can leave all of the other stuff as it is we'll also need to change some settings of the addressables so we'll go to the addressable assets data that you is automatically created for us we'll select the addressable asset setting and in here we want to make sure that you take the build remote catalog and you set the build and load paths to custom the build path you will set it to remote. build path and the load path will be remote. loadpath then we will need to scroll down and find the packed asset script of object where we'll need to change the same thing so we will change the build and load paths to remote then we will go back to addressable assets data folder go to asset groups select the default local group and again we will set the buildt and lo paths to remote and lastly we will go to the schemes folder where we will select the default local group bundled asset group scheme and again set the path to the remote. buildpath and remote. loadpath and that should be all for the boring settings so we can now make a build of our game so just go to file build settings and build it somewhere and make sure that you have set your build platform to the correct one once we have built the game we'll also need to build our addressables and push them to the cloud because right now they are not actually stored in the actual project to do that just add any addressables into your addressable groups window so I have just added a simple prefab so that I don't have to be uploading tons of files and then in the addressable groups window we'll just click build new build and default build build script that was pretty quick now we'll go to our projects folder and we'll open the server data folder in which we have the build that we have made for me it is Windows and you want to copy all of the files that we have in here again go to cloud. unity.com select upload content and then we can drag all of the files in here hit upload files and once they are uploaded you need to refresh the page and create release this is important because if you don't do it those files will not actually be released and once the release was successfully created we can try playing our game in the build when you play it there is nothing in here but when I press W you will see that it will start downloading some information and soon all of the objects will appear so for the first time that you play the game it is obviously going to take a bit more time because we need to download all of the files but when we try playing it again and I will press W you can see that it is really quick now the the biggest benefit of using cloud with addressables is that now I can go back to Unity and change for example the prefab so I have just added one more ball with Cube and made them smaller now we all just go back to the address group make new build and again publish it to Unity cloud and after you upload the files again don't forget to create the release so now I can play the same build of the game and when I press w we can see that the objects are really showing differently even though I haven't actually downloaded a new build we have just published the changes to the cloud and unity has automatically downloaded them so you can see that addressables connected with unity Cloud make it really easy for us to push new changes to the players of our game the players will be able to load the game a lot quicker and when they are downloading it for the first time the download size will also be smaller I hope that this video was useful if you have any questions or suggestions drop them down to the comments don't forget to like subscribe subcribe and I will see you in next videos bye thanks for watching this video till the end if you are looking for a Unity C or bold tutor then I am here for you so feel free to send me a message to my Gmail and take a look at my website for more info I can help you with your personal projects or teach you anything about game development you would want to know you are welcome
Info
Channel: Freedom Coding
Views: 1,027
Rating: undefined out of 5
Keywords: Unity, Unity2D, UnityEngine, GameDevelopement, IndieGameDev, PCGames, Coding, C#, Easy, Tutorial, Education, Unity3D, Programming, Bolt, UnityTurorials
Id: v3IDTWkDkbg
Channel Id: undefined
Length: 15min 24sec (924 seconds)
Published: Fri Dec 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.