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

Bug What changed in InstantiateAsync in the Addressables since 1.18.9?

Discussion in 'Addressables' started by iamarugin, Mar 10, 2023.

  1. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    So in 1.18.9 InstantiateAsync when using AsyncOperationHandle continued to work at the same frame if asset and dependencies was already loaded.
    After 1.18.9 this is no longer the case, I see one frame delay every time even if I am instantiating the same asset 100 time during 100 frames.
    So what changed and is there a way to return old behaviour back in newer versions?
     
  2. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    Any help will be appreciated.
     
  3. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    Please...
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,609
    It's often better to just load the asset into a local field, and instantiate it normally from there.
     
  5. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Hi @iamarugin what version of Addressables did you upgrade to? In general InstantiateAsync is not recommended to be used due to the performance impacts.
     
  6. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    Hey @pillakirsten, latest 1.19.19 version. But any version from 1.18.10 up to 1.19.19 have the same issue. And 1.18.9 and below works as expected.
    I just trying to understand is this an intentional change or just a bug. I didn't find any notes about it in the changelog, so I am asking here.
     
  7. IronHelmet

    IronHelmet

    Joined:
    May 2, 2017
    Posts:
    85
    Can you please explain why you would not recommend this. As far as I'm aware "Addressables.InstantiateAsync with trackHandle set to true" is the only way to automatically track reference counts.
     
  8. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,609
    Because the other method I described means you don't need to track reference counts. Just load the result of an AssetReference into a local member, then release the reference's handle right away. That way you never have worry about counting references.
     
  9. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    There's more overhead involved with InstantiateAsync rather than using LoadAssetAsync and Object.Instantiate. It also doesn't scale well when unloading scenes and moving GameObject between scenes (i.e. DontDestroyOnLoad).

    Currently only LoadAssetAsync is used in the latest "loading assets" page. As mentioned above, you just need to release the handle returned by LoadAssetAsync. You can instantiate and destroy the GameObject as needed.
    https://docs.unity3d.com/Packages/com.unity.addressables@1.21/manual/load-assets.html
     
    spiney199 likes this.
  10. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    It would be great to add note to documentation for 1.18.9+ that InstantiateAsync always have at least one frame delay.
     
  11. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    Am I missing something or your description is made in confusing way? I mean operation handle is used to track references, so if you assign result into local variable, then you release the handle and the local variable will contain unloaded prefab with missing materials, meshes etc.
     
    Opeth001 likes this.