Search Unity

Convert extremely large scene to addressables without too much pain

Discussion in 'Addressables' started by radiantboy, Jul 15, 2019.

  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    844
    Hi guys, I have a ridiculously large scene which holds my entire game in it all at the same time. I turn on and off parts as they are needed, yes it uses a ton of ram lol. Im trying to move away from using ordinary Resources, for speed/performance and to get around the 4 gig texture limit, as well as allow my game files to be downloaded from a server somewhere.

    Is there a way to just make this entire scene addressable and build out asset bundles from it? I have read and watched a lot about asset bundles and addressables but I find it somehow confusing. What would be the best approach to convert this huge scene (>200meg) into using the asset bundles/addressables system to achieve the objectives mentioned above? Thanks.
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    156
    Sure, you can make the whole scene addressable, and load with Addressables.LoadSceneAsync. But you won't get much benefits. The whole scene turns into a bundle file, whenever you make an update, you need to redistribute the huge file.

    The common usage of addressable is on the actual asset level, you mark your images, animations, models as addressables, and load / update on demand.

    However, if you split the huge scene into some smaller sub scenes, then mark those scenes as addressables, and load them on demand, you can still get benefit from the system on some levels.

    Legacy Resource.Load can be migrated automatically, see more in migration guide.
     
    unity_bill and radiantboy like this.
  3. RobbyZ

    RobbyZ

    Joined:
    Apr 17, 2015
    Posts:
    16
    I am in the same boat. A couple massive scene files that I'd like to not get baked into massive bundle files. I think my ideal end result would a bunch of ~50mb bundles instead of a couple ~1gb bundles.

    It sounds like if the assets have addresses, they wouldn't get baked into the scene bundle, so it'd just be a matter of assigning addresses in a way that groups them into appropriate chunks? Has anyone written any scripts yet to go through levels and automatically assign addresses to the used assets semi-intelligently?

    (I haven't dug into the API yet, but hopefully there's an editor API function to set address, and some other general purposes Unity editor function to get an array of assets in use by a scene)
     
    Last edited: Jul 19, 2019
  4. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    829
    Just some notes to point you in the right direction...

    When a scene is built, some things are flattened into the scene, and some are not. Prefabs, for example, are. So if you have a scene, with a prefab instantiated in it, and you mark both the prefab and the scene as addressable, then your build winds up with two copies of the prefab. One flattened into the scene, and one it its own bundle.
    Textures and meshes, on the other hand, do not get flattened into the scene. So if you marked a texture from a scene as addressable, the scene will point to the texture that got pulled into its own bundle.

    In our own prototyping the best model we've come up with is a script that takes all the game objects on a scene, makes them prefabs, then replaces them with a proxy. That proxy can then have a script on it that instantiates the addressable prefab based on the camera's location. We don't yet have a clean and shareable version of this script, but are working on a demo to put in our Samples github.
     
    BTStone, RobbyZ and radiantboy like this.
  5. RobbyZ

    RobbyZ

    Joined:
    Apr 17, 2015
    Posts:
    16
    Thanks @unity_bill, that gives some great starting points. Can you confirm if AnimationClips and AudioClips will be flattened into the scene or to bundle (or more generally, is there a list of types of each category somewhere?) Already just getting the textures and meshes into their own bundle should help our filesize massively.
     
    Last edited: Jul 25, 2019
  6. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    829
    Prefabs (GameObjects) are the only things I'm sure get flattened. As far as I know, everything else doesn't. Which probably means there are a couple less-known things that get flattened unbeknownst to me. Or maybe it's just prefabs.
     
  7. MagicDesignEmerick

    MagicDesignEmerick

    Joined:
    Oct 4, 2017
    Posts:
    9
    So, when we have an instance of a prefab, addressable or not, it gets saved into the scene? I thought the scene only referenced the GUID of the prefab.
     
  8. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    156
    AssetReference only stores GUID, so not get flatten.
     
    unity_bill likes this.
  9. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    829
    Correct, and apologies if I was not clear. The only scenario I was talking about that flattens prefabs is if the prefab is instantiated into the scene being built.