Search Unity

Forced to loose a frame every time Addressables.LoadAsset is called

Discussion in 'Addressables' started by FabioFZynga, May 10, 2019.

  1. FabioFZynga

    FabioFZynga

    Joined:
    Sep 24, 2018
    Posts:
    8
    I've noticed that by calling Addressables.LoadAsset there is ALWAYS at least one frame delay before the loadTask completes even if the asset is stored locally, further more the Task seems to be updated by the main thread so there is no parallelism going on there and there!
    I get that the call is meant to be asynchronous but shouldn't the returned Task at least be updated on a parallel thread so we programmers can choose to wait for that Task to finish if we want to provide synchronous loads?
    At the very least I shouldn't be forced to loose a frame every time I want to load an asset..
    Is there any plan to fix this?

    Thank you!
     
    davidrochin likes this.
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    As to operating on another thread, we've looked into it, but it's not doable for many of the engine systems we're building on top of. We intend to look into it more to investigate.

    One of the key issues is that all the providers are using Async interfaces. If you wanted to trick addressables into being sync, you actually need to replace the providers, not just wait for the existing ones. We just posted a sample of doing that here: https://github.com/Unity-Technologies/Addressables-Sample
     
  3. FabioFZynga

    FabioFZynga

    Joined:
    Sep 24, 2018
    Posts:
    8
    Thank you unity_bill! Hope you guys find a way to resolve the 1 frame delay.. If I read correctly the Synch trick doesn't currently work for all modes and all platform so I'm not going to be using it in the end.. but good to know it is somehow possible.
     
    unity_bill likes this.
  4. davidrochin

    davidrochin

    Joined:
    Dec 17, 2015
    Posts:
    72
    Any news about this?
     
  5. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    You can wrap the system in your own asset manager, hold the references to already loaded objects, then when you request that asset, return
    Task.FromResult(obj)
    . I do exactly that in my project (though I use promises instead of Tasks, but that's a moot point).
     
  6. davidrochin

    davidrochin

    Joined:
    Dec 17, 2015
    Posts:
    72
    Yeah but that way the first time you load an object is always going to be asynchronous, right?
     
  7. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Yes. If you want synchronous, you will have to preload your assets and cache them somewhere, then you can synchronously instantiate from that cache.
     
    davidrochin likes this.
  8. davidrochin

    davidrochin

    Joined:
    Dec 17, 2015
    Posts:
    72
    Thanks for the info!
     
  9. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    As of Addressable 1.19, there is AsyncOperationHandle.WaitForCompletion() that force the load request to complete in the same frame like Resouces.Load. Example:
    Code (csharp):
    1.  
    2. var request = Addressables.LoadAssetAsync<Sprite>(path);
    3. request.WaitForCompletion());
    4.  
     
    davidrochin likes this.