Search Unity

Setting up scenes as addressables

Discussion in 'Addressables' started by Timbecile76, Sep 18, 2020.

  1. Timbecile76

    Timbecile76

    Joined:
    Jul 8, 2009
    Posts:
    248
    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?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    As far as I know:

    1) 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.


    2) 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.


    3) 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.
     
    Last edited: Sep 19, 2020
  3. Timbecile76

    Timbecile76

    Joined:
    Jul 8, 2009
    Posts:
    248
    Thanks Peter! and if I load the level at runtime, I just tell it to load the other bundle also? or will it do that automatically?
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Addressables loads the dependencies automatically, you just need load your scene bundle.
     
    unity_7zw9ebm9jBJwig likes this.
  5. Timbecile76

    Timbecile76

    Joined:
    Jul 8, 2009
    Posts:
    248
    you guys have been a great help. one more question though....what is the use of having different groups?
     
  6. Zampilo

    Zampilo

    Joined:
    May 6, 2018
    Posts:
    12
    hi but i wanna update new asset with new script. There are any way to do? Always update assets but no new scripts.
     
  7. Kultie

    Kultie

    Joined:
    Nov 14, 2018
    Posts:
    48
    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.
     
  8. LucasHehir

    LucasHehir

    Joined:
    May 7, 2020
    Posts:
    74
    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.
     
    Last edited: Oct 14, 2020
    hoangyenpham and andreiagmu like this.