Search Unity

Question Prefab referencing so many dependencies??

Discussion in 'Addressables' started by lejean, Oct 13, 2020.

  1. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    2020-10-13 12_59_23-.png

    This prefab is a simple coin pile that drops from enemies, but, when I look at the event viewer, the dependencies for the prefab are completely wrong.

    Half of those dependencies have absolutely no relation with the coin pile.

    The bundles are packed together by label though, so does this mean that the entire prefabs bundle for the group and all it's dependencies are loaded into memory just for one prefab?
     
  2. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
  3. m4gni2de

    m4gni2de

    Joined:
    May 30, 2018
    Posts:
    13
    Does the prefab coin reference other prefabs? I'd have to see the inspector on that particular prefab
     
  4. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    Nop it's just some scripts without prefabs, and an animator.

    The problem goes away when I build the bundle with all prefabs separately though.

    That's not how bundles work right?

    If you have an entire bundles with all your textures for example and a prefab uses 1 of those textures, the entire bundle and all its dependencies isn't loaded in right?
     
  5. m4gni2de

    m4gni2de

    Joined:
    May 30, 2018
    Posts:
    13
    If the bundle is set to pack together then I believe they will all share the dependencies since Unity will bundle them together.
     
  6. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    Blegh more issues to work around.

    If that's the case then I don't see how one could make big bundles.
    Then you'd have to practically make every single asset a single bundle except for maybe a model with a unique material and textures that aren't used anywhere else.

    I use alot of shared materials for example in my project so I'd have to make every material a separate bundle so all the other materials wouldnt be loaded.
     
  7. m4gni2de

    m4gni2de

    Joined:
    May 30, 2018
    Posts:
    13
    Can't you just set the bundle to Pack Separately?
     
  8. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    That's probably what I'm gonna have to do ye, but I wanted to avoid having hundreds of bundles.
    I feel like that's gonna be a nightmare to update the bundles on a remote server.

    Also I still want to know how this actually works, cause the docs actually comment on this.
    When the compression is LZ4 the bundles don't need to be completely loaded and it can just read in chunks or something.

    If only a unity dev could give some info on this.
     
  9. m4gni2de

    m4gni2de

    Joined:
    May 30, 2018
    Posts:
    13
    Yeah sorry I can't be as much help as a Unity dev. I just kind of deal with that dependency thing with my remote bundles, and honestly I haven't had any problems with performance on mobile during my testing.
     
  10. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    Howdy! I'll kick this over to the team, and share any insight they have!
     
  11. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    We had similar issues with dependency management in our current production project. I've tried different strategies for setting up the bundles but in the end it all turned out to be too much manual work so we've started to use https://github.com/favoyang/unity-addressable-importer to automatically setup bundles for each of our "atomic" assets (like "objects" with all their direct dependencies). This greatly improved our iteration speed (no more setup of bundles for new objects!) and also greatly reduced our build sizes due to vastly better laid out bundles with less duplication and minimal dependencies. (We now have like 10GB of data in ~600 bundles that builds in ~2.5h and we may look into strategies to merge bundles into larger files for less I/O overhead)
     
  12. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    @lejean yeah I think your pack by labels is what's messing you up. Because your coins are packed in with all your other prefabs, we have to include all dependencies in your prefab bundle. And if any of those dependent bundles have other dependencies those will also have to be loaded.

    Just a suggestion, I probably wouldn't use the pack by label feature to pack all the same types of assets. I'd try and group them based on things I knew would likely need to be loaded at the same time. "level 1" or "treasure room" labels for everything you'd need for a given scene.
     
    FlightOfOne and lejean like this.
  13. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    Thx but then what do I do with stuff like shared materials/animations/textures that could be used anywhere?
     
  14. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    Move them into a separate bundle. The SBP will detect the dependencies and reference the "shared bundle" wherever an asset from within it is used. Addressables will then take care of loading those in the correct order, refcounting, unloading etc.
    What you shouldn't do is, use assets in a build (e.g. a model that is in a scene that is included in the build settings) as well as in bundles. That will with no doubt create duplicates as you need to have it in your build as well as the bundle. You'd need to opt-in to a "full addressables" build in that case, where all your assets, scenes etc. are put into bundles.
     
  15. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    @lejean I agree with @einWikinger, shared assets should be moved into their own bundle. If you use the Analyze tool there's a rule you can run to check for duplicate assets in multiple groups/bundles. Whatever it detects you can "fix" and it'll move all those assets into a single monolithic group (which you can then edit and change as needed). You want to avoid having shared assets built into every single AssetBundle that uses them if you can. That'll cause a lot of bloat in your builds.