Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simpler Alternative to Addressables.

Discussion in 'Addressables' started by locus84, Feb 3, 2020.

  1. petitbas

    petitbas

    Joined:
    Sep 9, 2014
    Posts:
    17
    I tried it again this morning, from scratch on windows, works reliably. Copy the project over to a Mac, with the exact same settings, build remote and local for that platform and I get the same error.

    GetManifest is being called in TitleScene.cs after GameManager.cs has loaded it.
     
  2. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119

    Got it! I'll check on mac!
     
  3. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Can you try again with latest commit?
    I found I forgot attaching "file://" prefix for some platforms.

    From my side, I've checked it runs well both on windows/macos.
     
  4. petitbas

    petitbas

    Joined:
    Sep 9, 2014
    Posts:
    17
    Awesome! That did the trick.
     
    locus84 likes this.
  5. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Very nice. A few clicks and it works. Nice and simple. I was wondering how dependencies are handled, if at all? I am happy to load things in the correct order manually, but how does that work exactly? ie BundleA has shared stuff in it (shaders), BundleB has a material that uses shader from BundleA.
     
  6. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    You can see how it handle via BundleBuildLog.txt in output folder

    Without Shared Bundle
    WithoutExplicitShared.png

    With Shared Bundle
    WithExplicitShared.png
     
  7. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi guys, 1.0.5 version is out with a few improvements.

    1. [update] added "open" button for each bundle output folder.
    2. [update] added functionality to log duplicate assets in bundles.
    3. [update] added 'dry build' functionality to get log file in #2 without actually building bundles.
    4. [fix] fix file path for some editor/runtime platforms(thx to petitbas).
     
    SugoiDev and Prodigga like this.
  8. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Hi, sorry for the confusion, I guess I meant that I wasn't sure how exactly to wire up the dependencies. If I create 2 bundles, where bundle A depends on bundle B, would the system just 'know' not to duplicate bundle B's assets?

    And secondly, how would you 'load' the dependency at runtime? Do I just LoadAll<Object> on Bundle B before loading anything from Bundle A?
     
  9. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    For the first question, if assets in bundle B are all included bundle A, then bundle A will be depend on B, other than that, each bundle will have their own assets duplicated, this is not about this system, it's about unity's bundle build pipline.

    And second, this system load up entire bundles at runtime. but they have know dependencies to utilize memory releasing feature. In short, bundle dependencies are written in Manifest.json
     
  10. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    So from my part, nothing is required except load whatever I want to load from Bundle A - Bundle B will automagically be loaded?
     
  11. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Exactly, you don't have to do anything for deps control, it just works.
    Like how Resources.Load works.

    Keep in mind you can also unload your assets using provided apis. which unload related bundles(this is where we need dependency data internally) and releases memory automatically.
     
    andreiagmu, aka3eka and Prodigga like this.
  12. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hey, this looks really cool! I'm thinking to the future of my game and am going to need a way to easily setup the asset structure to allow patching, so trying to decide between something like this and rolling my own. Does this system handle shader stripping automatically like addressables?
     
  13. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Because you ask the question, I think you better off just using Addressables. It may have it's flaws but it's feature packed and is supported officially by Unity. Having a sync layer on top of addressables is not that hard and you get the best of both worlds.
     
  14. petitbas

    petitbas

    Joined:
    Sep 9, 2014
    Posts:
    17
    When I instantiate async like this:
    Code (CSharp):
    1.   using (var loadReq = BundleManager.LoadAsync<GameObject>("Prefab", "PrefabName"))
    2.             {
    3.                 yield return loadReq;
    4.                 var instance = BundleManager.Instantiate(loadReq.Asset);
    5.             }
    and later on destroy(instance) when it's no longer needed, memory doesn't get released and I run out of ram on mobile. @locus84 have you run into this?
     
  15. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Can you give me more information?

    //show log message
    BundleManager.LogMessages = true;

    //show some ongui elements for debugging
    BundleManager.ShowDebugGUI = true;

    using this?

    Mine works fine.
     
  16. Da_Neel

    Da_Neel

    Joined:
    Dec 29, 2013
    Posts:
    15
    Does it work with Windows standalone build?
     
  17. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Yes but I recommend other patch solution for desktop, there are a lot in assetstore, and steam has built in one
     
    Last edited: Jun 11, 2020
  18. Da_Neel

    Da_Neel

    Joined:
    Dec 29, 2013
    Posts:
    15
    Can you point me at those? I can't find anything useful
     
  19. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi guys, a 1.0.6 is out with a great new feature!

    This is called *Auto Create Shared Bundles*

    The system will analyze each of your asset dependency tree.
    And find out top-most duplicate asset entries from it, make it into a shared bundle.

    By using this, you'll find no duplicated assets in your patch!
    Also, I found this is much easier to find out the health status of my bundle settings :(... (which was dirty)
     
    Last edited: Jul 3, 2020
  20. petitbas

    petitbas

    Joined:
    Sep 9, 2014
    Posts:
    17
    Calling BundleManager.GetManifest() while there's no internet connection causes a NetworkError.

    Has anyone found a reliable way of handling loss of internet connectivity and working with the currently cached bundles?
     
    locus84 likes this.
  21. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    That's an unexpected use case for me, but it has already a cached manifest, if you want to use it.

    Code (CSharp):
    1. AssetbundleBuildManifest.TryParse(PlayerPrefs.GetString("CachedManifest", string.Empty), out var cachedManifest) ;
    Try this when you meet Network error
     
    petitbas likes this.
  22. petitbas

    petitbas

    Joined:
    Sep 9, 2014
    Posts:
    17
    Sweet. That did the trick.
     
    locus84 likes this.
  23. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    What does "Asset Bundle 'xxxxxx' is invalid because it contains mixed Asset and Scene types" mean?
     
  24. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Means you cannot put a scene with non-scene asset.
     
  25. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Ah, gotcha - thanks for the explanation. I didn't realize that scenes need to be separate from other assets.

    I've never used asset bundles before so perhaps someone can help me understand the common use scenario. I could be going about this all wrong.

    So here's my plan... Currently my game is getting close to 100MB in apk form (the max apk size that google allows). I was thinking that I can break out some of the models/materials/prefabs/textures/etc into a "CommonBundle". That would allow people to download the small game apk from the app store and then the first thing it would do is download the CommonBundle. So far so good.

    I also may want to use bundles for patches and fixes, but I don't anticipate any issues with that.

    As time goes on I'll be adding bonus "levels/maps" which are just scenes and additional assets - Downloadable Content packs. So my thought was to make something like DlcPack01Bundle that contains 2 or 3 "levels/maps" (scenes) along with some new enemy models/gun models/props/materials/textures/pfx/sounds/etc. So I did that, and that's when I got the error above about scenes needing to be in separate bundles.

    Is there a way to package scenes like all the other assets into a DLC bundle? If not, how are you guys organizing your bundles? Is my bundle organization plan completely wrong?? Are bundles even intended for DLC, or should I be using a different technology for DLC?
     
  26. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    So I'm not really sure how other people are handling the issue of scenes requiring separate bundles... but here's what I've come up with.

    DLC bundles include everything needed except for the scene. I also have a ScenesBundle such that whenever I make a new DLC package, I place the scenes inside of ScenesBundle, and then when people download the Dlc01Bundle or whatever, they also need to download an updated ScenesBundle that replaces the old ScenesBundle. I'd rather not have to separate them, but I don't know of a way around it.
     
  27. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Now I have another question... when I build the bundles, I'm finding that there are some URP shaders that are in common, causing three bundles to be auto-built. This is what the build output looks like:


    Build Time : 2020-07-20 16:53:12
    Possible shared bundles will be created..
    Shared_31321ba15b8f8eb4c954353edc038b1d - Packages/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat is referenced by
    - CommonBundle
    - FxBundle
    - IslandBundle
    - ScenesBundle
    Shared_933532a4fcc9baf4fa0491de14d08ed7 - Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader is referenced by
    - CommonBundle
    - FxBundle
    - IslandBundle
    - ScenesBundle
    Shared_8d2bb70cbf9db8d4da26e15b26e74248 - Packages/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader is referenced by
    - CommonBundle
    - IslandBundle
    - ScenesBundle


    And the folder output looks like this:

    upload_2020-7-20_17-4-46.png

    So rather than distributing 3 extra bundles with the program, should I make a SharedShaderBundle and put those 3 shaders in it? That seems like it would be really weird removing a shader from "Packages/com.unity.render-pipelines.universal/Shaders/" and placing it into a separate package. I avoid modifying anything inside of the Packages folder as much as possible.
     
    locus84 likes this.
  28. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi there, looks like you want to define bundles from packages.
    I haven't tried that before, but I'll look into it in this weekend. I might add ability to select a folder inside packages.
    If you think your bundle is quite big and having those shaders multiple times(as it's quite small) is acceptable, you can always disable 'auto create shared bundle' toggle. this will remove automatic shared bundle generation.
     
    lclemens likes this.
  29. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    You'll need separate bundle tags for that, which defines dependencies among them.
    Let's say you have three tags, default, dlc1, and dlc2. and tag your asset bundles with it.

    You have to manage required assetbundle list according to user inventory.
    For example, a user just bought only main package, his bundle list is only 'default'
    If he bought dlc2, it'll be 'default' and 'dlc2'.
     
  30. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    That's good to know about the tags. I wish there was a way to put scenes in the same bundle as other assets so that players would only need to download a single bundle, but I guess I can work around it for now.
     
  31. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Sadly, Unity's assetbundle does not allow it because scene's packing prodcedure is different.
     
  32. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119

    Bad news, I found it's difficult to check the path is from packages or not.(because there's a lot of ways to include a package into a project)
    I'll keep looking into it but for now, available options are just keep shared bundle or create your own material that references the shaders and make them into a shared bundle.
    I'll ping here when I find profer way to achieve this.
     
  33. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Thanks for looking into it! No worries, creating a separate shared bundle with multiple materials and shaders seems like a decent solution.
     
    locus84 likes this.
  34. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi guys, a 1.0.7 is out with some minor improvements

    1. As I see many of you guys think of DLC kind of system.
    I've added a parameter 'subset bundle names' which you can provide along with manifest.
    This is good to keep already downloaded bundles in cache, and will automatically resolve dependencies.(which is must for AutoCreateSharedBundle feature)
    Download function now all properly unload bundles not interested.

    2. Also added TryGetCachedManifest to support offline play(thx to @petitbas).
     
    andreiagmu and SugoiDev like this.
  35. alireza_95

    alireza_95

    Joined:
    Mar 3, 2018
    Posts:
    5
    Hey there, I know this might not be completely relevent here.,but I am hoping someone here will have experience with these two issues. I have moved from addressables to locus since the simplicity in design helps a lot in our project. and also for some reason addressables has a hidden web request to remote server when initialized which i can not change the timeout time of or configure in anyway. and the game will get stuck for 2 minutes if there is a problem with the request.


    1- since the target platform is android i am unable to test the game in editor. i have solved the shader problem for models but the sprites and nessecary stuff fo text mesh pro will be missing.
    Even if i change target platform and rebuild in windows. the shaders work correctly but still the sprites are all missing and white.

    2- when adding new scenes or changing a scene (even if it is not included in any asset bundle) all the asset bundles containing a scene will be rebuilt. which means if i want my users to use the current version of assets they will have to redownload every scene they have downloaded before to use them. i am guessing this has to do something with built in shaders and that unity builds its own bundle and being rebuilt means all scenes have to be rebuilt. but i am not sure how i can solve it. can including all shaders in another asset bundle solve this problem?.
     
  36. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi there,
    1. I can't understand why it occurs, can you send me minimal test project so I can reproduce?
    2. In that case, you should split the scene asset bundle. If the scene you added is even not associated assetbundles, that's weird one, haven't seen before.

    You should check those problems with a fresh project as much as possible(which i do everytime i see something wrong and can't find any clues).
     
  37. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    Hi,

    When testing this out as a possible replacement for AddressableAssets, I was testing the functionality to have nested folders in the bundles and I think I may have stumbled across a bug.

    In Runtime/AssetBundleUtilities.cs, line 44, the
    Path.Combine
    combines the
    dirPrefix
    , with the
    dir.Name
    , I think this should be the
    dirPrefix
    combined with
    subDir.Name
    .

    If I have a folder structure:

    RemoteAssets (dir)
    --|
    --+ Sprite.prefab
    --|
    --+ Test (dir)
    ----|
    ----+ Another.prefab


    I get an asset bundle with AssetNames:

    Sprite
    RemoteAssets/Another


    I would have expected:

    Sprite
    Test/Another


    Making this change makes it behave as expected here.


    Cheers


    Paul
     
    Last edited: Sep 30, 2020
    locus84 likes this.
  38. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Seems like you're correct, thank you for the reporting!
    Fixed in latest version.
     
  39. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    Another small issue, hope you don't mind me mentioning it here, if you'd rather I add a bug to the project, just let me know.

    In
    BundleManager.cs
    , line 292, you set the current index for the bundle being downloaded to the next index, but don't reset the progress, this means that for some yields after that, until further down where the progress is updated, it will remain at the last bundle's value, i.e. high, which results in some strange jumping around of the progress value.

    I noticed this because I've written something that calculates the overall total and works out the progress towards that overall total, meaning I have a single progress bar that goes from 0 to 1 for the total download process, rather than 0 to 1 for each bundle, happy to share if it's of use to anyone, probably not efficient or well coded, but it works.


    Paul
     
  40. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Thank you for another report!

    But maybe you mean line 310?, if you do, that's intended, as you can see, there's two yield inside the block, one is quit, the other is waiting, which is right after SetProgress.

    You can free to fork and share your modifications here!
     
  41. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    Yes, sorry, line 310, I must have checked against an out of date view. All I know is that if I don't add
    Code (csharp):
    1. result.SetProgress(0.0f);
    on the line straight after the
    Code (csharp):
    1. result.SetCurrentIndex(i);
    (currently showing as line 310), then I get a few yields in my progress code that show the new index, but the old progress, so my progress bar jumps up for a few frames, and then drops back, adding that line solves it.

    Paul
     
  42. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    That should not happen in original code.

    I think that's because in your commit "Implement URL transform interface." you've added another yield instruction inside

    var cd = new CoroutineWithData(s_Helper, URLTransformer.TransformURL(loadURL));
    yield return cd.Coroutine;

    Regards.
     
  43. tractionsim

    tractionsim

    Joined:
    Aug 4, 2019
    Posts:
    3
    Nice package! Thank you so much. Addressables is not for me, I personally doesn't like some over-engineering, UI and strange (again for me) terminology.
    Won't you add something like AssetReference to the package so the system is functionally complete and usable out of the box?
    Yes, one can use the provided samples, but why not to have a ready plug'n'play class that can be used for the referenced asset and it will handle all the internals (loading, releasing, etc).
    Are you going to provide smth like built-in simple catalogue so bundled assets can be searched and introspected?
     
  44. tractionsim

    tractionsim

    Joined:
    Aug 4, 2019
    Posts:
    3
    BTW did you manage to use package in edit-mode tests? It's not working in the
    "UseAssetDatabase mode" for me because #if UNITY_EDITOR is not enabled in packages.
     
  45. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    I have added sample code in ReadMe.md, as well as youtube video.

    If it's not enough you think, I would consider adding sample project in tha package.

    About Edit mode test, I'll look into it in this(or next) weekend!
     
  46. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    My bad, well spotted, apologies.
     
  47. elfasito

    elfasito

    Joined:
    Jul 4, 2017
    Posts:
    51
    Hello, noob question.
    this works with firebase storage too?.
    because im using a gs:// link, not a http:// one as remote server
     
  48. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    I have no idea for that, at least unity handles file://, http(s):// scheme, can you gimme a link of a sample file so I can test?
     
  49. Aoedipus

    Aoedipus

    Joined:
    Jan 31, 2019
    Posts:
    25
    Hi, and first off thanks for the addressables alternative! A minor issue has come up. I've been unable to run the sample scene since creating a second AssetbundleBuildSettings file associated with my main project. As soon as I hit play, the build settings revert back to an inactive state and default to the new one. I'm having some remote download issues that I want to test against the sample scene (or any other simpler test scene I create). Any tips would be appreciated. (Win7, v2020.1.8f1)
     
    Last edited: Oct 25, 2020
  50. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi there.
    Actually this project is tested only on AOS/IOS and desktop platforms.
    Will test and ping here.

    Regards.