Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

How to load assets synchronously in addressable asset system.

Discussion in 'Addressables' started by Lee-Gyein, Oct 9, 2019.

  1. Lee-Gyein

    Lee-Gyein

    Joined:
    Apr 28, 2016
    Posts:
    1
    Is Unity planing to support for synchronous loading of Addressable Asset?

    We are developing a game and recently we've tried to migrate from old asset bundle system to addressable asset system.

    However Our system was already constructed to load almost resources synchronously and it would be so painful and take a lot of time to change it asynchronous. So we are looking for a way to load resources synchronously with addressable asset.

    First I used 'LoadAssetAsync' function like below codes

    var handler = Addressables.LoadAssetAsync<GameObject>("SomeAddress");
    while (!handler.IsDone);

    Debug.Log("This line will never be called!!");

    But In this case, the property of 'IsDone' never changed. Is it right? If it is just a bug in the latest version of addressables I hope that unity fix it ASAP.

    And I've made some synchronous provider by referencing "SyncAddressables project in https://github.com/Unity-Technologies/Addressables-Sample"
    Unfortunately this wasn't able to cover all cases too. In some cases like loading asset bundle with some dependencies, It didn't work.

    If Unity doesn't have a plan to support for it, Is there any other way to deal this? Is to change sync loading to async loading the only way I can?

    Thanks
     
    Last edited: Oct 9, 2019
  2. StrongCube

    StrongCube

    Joined:
    Nov 22, 2016
    Posts:
    48
    No, addressables is dead asset
     
  3. Zimbres

    Zimbres

    Joined:
    Nov 17, 2014
    Posts:
    102
    Excuse me sir? I'm starting to research on the matter, is Addressables ... dead? Muerto? Expired? Under six feet of dirt? With ants on its mouth?
     
  4. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    69
    He may be just disappointed at the slow or nearly zero response from unity in this forum. Addressable now have many bugs, just see these bug report threads, for me I encountered:

    1. AssetReferenceT<T>.editorAsset is broken if T is subAsset like Sprite.
    2. AddressableWindow and AssetReferenceGUI is extremely slow if you have thousands of assets. Every click takes you 3-5 seconds even when project is saved on SSD.
    3. Addressable build is extremely slow compares to old fashion Resources Or Asset Bundles, it also ignores caches which makes it worse.
    4. All these slow operations are not because of high usage of CPU, because I spent around two weeks to migrate and reordered my entire project, I wrote many automation script like rename all assets in side group, whenever I choose to automatically do something or build the project from scratch, I can play one hour World of Warcraft with high settings and solid 60FPS. I leveled up 2 new characters to lv.120 while waiting for addressable to work.

    it's basically functional, also you can modify the source code if you now how to fix. But still, it's always better to hear more from the dev team, makes people confident.
     
    Last edited: Feb 4, 2020
    Patrick_PS and Zimbres like this.
  5. Zimbres

    Zimbres

    Joined:
    Nov 17, 2014
    Posts:
    102
    Your patience and serenity on reporting so heavy drawbacks is admirable. I.... think that I will try to load/unload stuff using other feature, maybe.
     
  6. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    69
    I would suggest using AssetBundle.LoadAsync. if some day addressable become truly production ready, it's easier to migrate.

    As for those thing that must be load synchronously, I can share some of my methods:

    1. You could split your prefab into two or even more parts, one contains minimal scripts, others contains actual assets. When the main part is loaded and gets enabled, it can load assets asynchronously. For example, create a character with basic script, rigidbody and collider and so on, that character is already fully functional even it's invisible for some frames. Then load everything else.

    2. Create a scriptable object called asset linker. It's contains all assets' path that must be ready to use when running games. When game started, load that container first, then wait for loading everything it links, then load your start menu. If you are in play-mode, you could do AssetDataBase.Load(path) instead of AssetBundle.LoadAsync(path) to loading everything synchronously, so all data are ready when you use them.

    3. Make your functions as instructions. For example, if you need to play some particles at some location, instead of create a game object immediately, you create a struct contains (path, position, rotation) and put it into a list. Make a system examining this list every update, see if that particle object is actually loaded and instantiated, if it does, put it at target location and delete this instruction.

    Overall,
    method 1 is most used when dealing with characters, gears, weapons, bullets...You need to do GetComponent() then set some data when they are created. Things gets far more complex if you have to do this asynchronously, especially when dealing with edge cases like you should destroy that character while it's assets are still loading...

    method 2 is most used for loading game database and other assets that lives through the entire game life-time.

    method 3 is most used when dealing with particles, audio clips...These things just need to spawn at some location, and that's all.

    These are just personal experiences, not best practice.
     
    flamingogs likes this.
  7. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    93
    @Zimbres Dont let him scare you away from addressables. There are definitely some cons, but there are also a lot of things that are way better than using traditional AssetBundles.

    For one, using the older system the proper way took a ton of work, Addressables handles a lot of that work for you with out needing anything extra.

    Addressables definitely does have bugs, and it has improved a lot even in the past few months.
     
  8. Zimbres

    Zimbres

    Joined:
    Nov 17, 2014
    Posts:
    102
    My thing is, I'm planning on how to load content for a simple open-world game, and I'm still on planning phase. I must say... I'm scared to adopt something from Unity if there's no certainty. Unity's history tells that it's better to work with fully developed features and dont take anything as granted. It reminds me on how much time it's new input system is being developed, how much time nested prefabs took to happen, etc.

    I dont know I'm crazy or not, but I'm thinking on just use some system for loading and unloading scenes async. It have it's problems... but I'm still researching it.
     
  9. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    160
    If you're scared to use addressables because it's still getting patches, just implement your system with assetbundles. Then when you feel addressables is stable enough for you, it's relatively easy to convert.
     
  10. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    125
    @Topic - Just use async & await, and you have a synchronous loading. In my project all assets are preloaded before the game starts which is almost identical to synchronous loading.

    @Addressables - People reporting problems here witch addressable probably has a very little experience with the package. There are definitely a lot of cons, but the number of benefits greatly outweighs those. I have 6GB in total of asset bundles and manually managing those with old workflow is not feasible.

    Ultimately, if there is some problematic issues with the asset itself, you could fix or rewrite it yourself, you have a full source code.
     
unityunity