Search Unity

Question Scenes as addressables, what does it mean?

Discussion in 'Addressables' started by iSinner, Sep 24, 2020.

  1. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    201
    Can someone help me understand what does it mean to put a scene in addressables? i can't find a precise explanation, or any explanation for that matter about scenes.

    How does it work? more precisely, if i put a scene into addressables, does this mean that all that is directly referenced in that scene will be pulled into addressables on build?

    Can i use direct references to assets in the scene and work with them as if they are local(i.e. write synchronous code for them), or do i have to reference all the assets in the scene as addressable as well, even though i marked the scene as addressable?

    What about script components on objects in the hierarchy, will they be pulled into addressables on build?

    What if i have prefab instances in a scene, the concept of prefabs is non existent in a built application, will prefabs themselves be pulled in addressables in this case?
     
    Symgy likes this.
  2. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    201
    A lot of views but no replies.

    Can someone maybe point me to some documentation that explains how scenes behave exactly and what exactly does it mean for all referenced assets in the scene, to put a scene in addressables? I've looked, i've read, there is only how to use the loading scene api, but nothing about the questions i mentioned above.

    I have found this topic. Can someone confirm this is how it works?
     
    Last edited: Sep 25, 2020
  3. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    According to my current knowledge:
    Everything that's in the scene that's not addressable will be build into the scene making the scene bundle larger in size.
    Meaning if you change anything in the scene, you have to download all built in assets also.

    If you mark the assets in the scene addressable, the scene bundle will be smaller so any changes you make in the scene will just update the "scene data" without all the assets, which is what you want.

    All static addressable assets will just be loaded from the bundles, you don't have to do anything special like instantiate or something. It will just be loaded with the scene.

    Now if you have a script in the scene that has a direct reference to a prefab that you instantiate at some point, that prefab will be included in the scene bundle as well unless you make that prefab addressable but that means you have to change your code to the addressable version like "Addressables.instantiateAsync" etc..
     
    Trunksome, Symgy and iSinner like this.
  4. LuGus-Jan

    LuGus-Jan

    Joined:
    Oct 3, 2016
    Posts:
    179
    Hey @iSinner

    I can give you my insights or knowledge so far of what I've seen with scenes being used in Addressables.

    We have quite a bit of scenes in the Addressables system, and I just dropped them in there and with a little of script adjustments in where we load our levels, it worked pretty much instantly.

    Though in recent days I've also been struggling with the content that gets included inside these scenes. Our build time has increased quite a bit and the size of our player builds has exploded (we went from 4GB install size to ±17GB). I didn't pay too much attention to it since I've been updating our project to use Addressables instead of plain old Resources and Asset Bundles.

    We just released our update and I'm inspecting now what is causing this massive increase in build size. I do notice that my scene bundles are quite big. Addressables has a tool to inspect which assets are packed explicitly versus implicitly, and here's where I think comes the issue: each and every scene includes a copy of the asset (prefab, texture, material etc) in its own bundle. I'm currently at a point where I'm including each of these assets referenced by my scenes to include them in their own bundles, in the hopes that just a single copy of the asset is taken up in the system, and also, to reduce the build times so that only the bundle that contains the item gets updated instead of repacking/building everything with the slightest change to a single prefab.

    So I gather the following things from my experiences thus far:
    - If you don't include prefabs or other assets in Addressables, your scene bundles will just copy them over inside their own bundle. You don't need to do anything special (this aspect has worked well for us thus far). For example: if you put a prefab in your scene which is not Addressable, it will just take a copy of the prefab and bundle it with the scene. (this also uncouples the prefab from the one that is shipped with your player. So any changes you make afterwards to your player will not automatically propagate to the bundle, unless you rebuild the bundle)
    - If you do assign your (sub) assets to Addressables, I believe it will create some kind of dependency chain. If you include a prefab in your scene that is Addressable, it will not make a copy of it like it does in the first point, but instead load that object from the prefab's own bundle. I also don't think you would need to do anything special regarding loading in these objects yourself first. Addressables does seem to have a good working dependency chaining system, though I can't confirm at the moment (as I'm still myself busy in this process :) )

    Not sure what you mean by this. Code in itself is never pulled in Addressables. That is always built with the player.
     
  5. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    201
    Thank you both a lot for your insights, that clears up a lot.

    @LuGus-Jan from your explanation about addressable references in scenes, i would sum up them as weak references. I think its perfectly analogous.

    Furthermore, addressable has analyze rules, and one of them looks for duplicate asset inclusions, does that not work for you with the scenes?