What are Addressables in Unity and How to use to them | Unity Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the unity addressable system is a super powerful feature which allows developers more control over how the instantiate objects into their scenes it can be useful for improving performance and saving memory in large worlds but the most exciting part is that it allows developers to load game objects into their game from a Cloud Server which means your game will have a smaller download size and quicker in source for your audience it also means that you can dynamically add content to your game without needing to push out the new update and in this video I'll be showing you how the addressable system works and how we can load Dynamic data into your game [Music] this video is brought to you by Sky games check the link in the description for more info so as a base I have the scene set up and when I press I we are using the standard instantiate method to instantiate an environment into the scene you can see this works as expected now in order to upgrade this to an addressable system we need to install the addressables package from package manager under Unity registry after it's installed we'll open up the main window under window Asset Management address bills and groups then click create addressable settings this window will be the place that stores the prefabs or assets that need to be used by the addressable system so since I'm going to be instantiating this environment prefab I'll drag and drop it into the groups window and now you'll see this asset is marked as addressable along with the file path to the asset now in my instantiation script I'll add using Unity engine dot addressable assets and unityengine.resourcemanagement.async operations and now instead of grabbing a reference to a game object we need to get a reference of type asset reference game object this will allow us only to assign game objects which have been marked as addressable in the inspector so I'll assign my environment prefab since it's already marked as addressable and just a side note if I drag a prefab into the slot which is not marked as addressable it will automatically be added to your addressable group now to instantiate this environment there's a couple different options the first way is after I press the I key we load the environment into RAM by saying environment.load asset async and this happens asynchronously so in order for us to know when the environment is finished loading we can add dot completed plus equals un addressable loaded and we'll create that method with an async operation handle of type game object as a parameter then we'll just check if handle.status is equal to async operation status dot succeeded and if it is then we'll instantiate the result else we'll just log an error so what's happening here is we are loading the environment into your computer's RAM asynchronously and then once it has completed the loading process we call this method which instantiates the game object into our scene now if we run the game and I press I you can see my environment is successfully loaded and instantiated now because our addressable asset is specifically a game object we can actually just call environment.instantiate async which will handle loading and instantiation for you so if we test this one more time you can see that when I press I the same goal is achieved but in only one line of code now there's two more quick tips I'd like to show you before we make our addressables load from the server the first one is deleting the instantiated addressables correctly and to do that we just need a game object to store a reference to the object we instantiated which I'll call instance reference then this time we'll rename our unaddressable loaded function to un addressable instantiated and we'll call that function once our environment has finished instantiating then if it succeeded we'll set instance reference equal to handle.result okay so now we have a reference to the game object we instantiated and to unload it from memory we'll check if the D key is pressed then we say environment.release instance with instance reference as a parameter and now you can see I can instantiate and delete my environment as if it was a normal game object then one more quick tip before we get to the interesting stuff if you're following along you might have noticed that there isn't an asset reference class for all types for example you can see I can't add an asset reference audio clip without getting an error in that case all you need to do is create your own asset reference audio clip class which derives from asset reference T of type audio clip then to get rid of the error click on the class name and press alt plus enter and select generate Constructor in Visual Studio then you just need to add the system.serializable attribute to show it in the inspector and that's it you can now use audio clip specific addressables okay now for my favorite part in order to load addressables from a server Unity has made it super easy to do that and you might be surprised that we don't even need to modify any code to get this to work to get started in your assets folder open addressable assets data and on the addressable asset settings you'll want to enable build remote catalog and set build and load pods to remote then scroll down and click on packed assets and in here you can just make sure that the bold and load ports is set to custom but it points to the remote Dot buildpath and remote dot load path then you'll want to go into the asset groups folder and click on default local group and here you'll want to make sure update restriction is set to can change Post Release and your build pods are set to the same as before then in the schemas folder make sure that the middle settings have the same build and load pods as well now that those are set up we can go back to our addressable assets data folder and in our address for asset settings click manage profiles then we'll set our remote to custom and we can leave the build path as is but for our load path you'll want to make sure that you paste your file server's URL in here for this tutorial I'll be using unity's content delivery Network solution for hosting my files but it's basically the same process for other services like digital Ocean or AWS so to get started with unity CDN go to dashboard.unity3d.com and sign in then go to liveops and click cloud content delivery you'll be asked to enter your payment info but you won't get charged unless you go over the 50 gigabyte limit so it'll be perfect for testing purposes once that is set up click on buckets and follow the on-screen instructions to create your first bucket then you'll want to open your bucket and just make sure that there aren't any entries in it then click on upload content and inside Unity we need to actually compile our addressables into asset bundles but before I compile my addressables I'm going to swap out the entire environment for some small props just so I don't have to upload massive files to the server now you can see my props being instantiated locally so now to compile the files you'll click on build new build and then default build script then once that is done you can navigate to your projects folder and inside the server data folder open the folder with your build Target name minus Standalone windows 64. and these are all the files you need to upload to your file server so we'll click on upload files and once it's done refresh the page then you need to make sure you create a release with the files you uploaded then go to addressable remote path URLs and here you'll want to make sure you copy the URL that says badge latest because this URL will always point to the latest release you have made but the other URL only points to a specific release then in unity open your addressable profiles and in the remote load path paste in the URL you just copied and that's that if we create a bold now and test it out you'll notice the first time takes longer to load and that's because your computer is busy downloading the files from your server but once they are downloaded they are stored permanently on the player's machine so they only have to re-download the files if something changes it is also super easy to add loading screens but that's a topic for another video now I'm going to show you where the real magic happens in unity I'm going to edit my props addressable by moving the rock as well as adding a completely different model to the addressable then we need to build new asset bundle files but before doing that I'd recommend deleting your old asset bundle files from your server data folder now this time instead of making a new build you'll want to update the previous one and you'll want to go to your addressable asset status folder then windows and double-click the addressables contentstate.bin file and wait for the new build to complete if your dot bin file is not there you could try searching in your project folder for any kind of dot bin file once your compilation is complete head over to your file server and remove all entries then upload the new file stored in the server data folder and you'll see it takes longer to upload because I added more content to the addressable file when your file upload is complete make sure to create a new release then give it a few seconds and open up the exact same executable file we opened last time and when I press I it obviously takes longer to download the new content but as you can see the game has now updated its content without any kind of updates to the executable file this is such a powerful feature in unity and I hope it helps you create better games if you enjoyed this video or learned anything from it a like or subscribe would be much appreciated and don't forget to go check out our website at skygames.com
Info
Channel: Skye Games
Views: 13,231
Rating: undefined out of 5
Keywords: Unity Tutorial, Unity Addressables, Unity addressables tutorial, Unity Beginner Tutorial, Unity Advanced Tutorial, Unity, How to Unity, Unity Advanced Features, game dev, assetbundles unity, Unity Remote Content, Dynamic Content Unity, remote asset bundle, remote asset unity, addressables unity remote, unity addressables tutorial, unity asset bundle tutorial
Id: wEuFAA-Ktwc
Channel Id: undefined
Length: 9min 43sec (583 seconds)
Published: Wed Aug 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.