I’m looking into the possibility of using addressables for all my scenes, but I can’t find any documentation on how to set up a scene so that it’s completely encapsulated in an asset bundle (the scene, the prefabs, the textures/materials etc).
So how do I do it? Can I just make the scene an addressable bundle and it will add everything by itself? or do I have to add all the assets the scene uses as well? What happens if multiple scenes use the same prefab assets?
If you add a scene to a bundle, Unity pulls in all its dependencies into the bundle as well (unless see 2).
Example:
If your scene uses Tree.png, this texture would be part of the scene bundle. If multiple scenes contain this texture, it would be pulled into each scene bundle. You end up with duplicated assets in each bundle.
To overcome this behavior, you need to move content to separate bundles too. This allows Unity to share assets that are used by more than one scene.
Example:
Add Tree.png (or a bunch of trees) to a separate bundle. Now the scene bundle will no longer pull in a copy of tree.png, but loads it from the “tree bundle” instead.
Splitting shared content over multiple smaller bundles is extremely beneficial, here are a few reasons why:
It avoids having duplicated content in possibly each scene bundle.
It makes the overall content size smaller, because you don’t have duplicated content in each scene bundle.
It makes game updates smoother, because if you change the Tree.png, only the bundle with the tree needs to be updated, rather than every scene where this tree is used.
It makes builds faster, because if you change the Tree.png, only the bundle with the tree needs to be updated, rather than every scene where this tree is used.
You can’t update new script with the addressable. If you make any change to scripts you must rebuild the project and redistribute the build for the change to be apply. If you just add/remove script component of game object in scene then addressable got you cover.
But if you use addressable as your resource system then rebuilding project will be much faster so I don’t think rebuild because script change will be problem.
When you build your content bundles, each group is turned into a seperate bundle file containing each asset you’ve put in that group. When a part of your game requests an asset from Addressables, whether its a scene or anything else, Unity will automatically load the bundle file containing that asset (if it isnt already). So if everything is grouped cleverly, Unity will only load what it needs to at any given time.
This is really useful because, if you’ve got a big game or some big assets, you probably don’t want to load them all at once. Thats a common cause of bad performance. There’s no need to load your credits music at the start music, right? So you might have a ‘StartMenu’ bundle with all your start menu assets and a ‘Credits’ bundle with all your credits assets. Or even better, just make each scene addressable, use whichever assets you want in each and let the content build figure out the rest!
There are times where assets are shared between scenes and then duplicated, like Peter77 pointed out, so when you find an asset like that, maybe put it in its own seperate group (call it something like “Persistent”) to keep it easily shared. In that case, you shouldn’t ‘directly’ reference the asset in question, you should load it via an AssetReference or using asset labels. If you directly reference it, it’ll get duplicated anyway.
Just remember that bundle files can’t be automatically unloaded until nothing is left referencing them.