Search Unity

Bug AssetReference.InstantiateAsync on Addressables 1.18 calls Awake, OnEnable, and OnDestroy twice

Discussion in 'Addressables' started by JesseSTG, May 13, 2021.

  1. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Spawning a prefab with AssetReference.InstantiateAsync (in Addressables 1.18.4) calls Awake, OnEnable, and OnDestroy twice

    In Addressables version 1.18.4 and 1.18.2, spawning a prefab with AssetReference.InstantiateAsync calls the Awake, OnEnable, and OnDestroy events multiple times per attached MonoBehaviour. To reproduce:
    1. Open the attached SampleScene
    2. Enter play mode
    3. Exit play mode
    4. Look at the console. You will see 8 log entries which should look something like this:
    Code (csharp):
    1. SpawnedObject.Awake(<instance ID>)
    2. SpawnedObject.OnEnable(<instance ID>)
    3. SpawnedObject.Awake(<different instance ID>)
    4. SpawnedObject.OnEnable(<different instance ID>)
    5. SpawnedObject.Start(<different instance ID>)
    6. SpawnedObject.OnDestroy(<instance ID>)
    7. SpawnedObject.OnDisable(<different instance ID>)
    8. SpawnedObject.OnDestroy(<different instance ID>)
    The expected behavior is that there are only 5 log entries, one for each event that SpawnedObject implements (and each entry should display the same instance ID).

    Other important facts:
    • I am using Windows 10 and Unity 2021.1.6f1.
    • I have not tested this on other operating systems or Unity versions.
    • This does not occur on Addressables 1.17.17.
    • This happens on multiple build platforms.

    I already reported it directly with the bug reporter, but I've posted it publicly to save others time in troubleshooting.

    This is a pretty major bug. Come on guys, I know you're better than this.
     

    Attached Files:

    Last edited: May 14, 2021
    inyman likes this.
  2. jperry_oddgames

    jperry_oddgames

    Joined:
    Sep 18, 2017
    Posts:
    62
    phobos2077 and JesseSTG like this.
  3. stephen_mor

    stephen_mor

    Joined:
    Apr 3, 2019
    Posts:
    7
    Also hitting this issue after upgrading addressables to 1.18.4. A lot of our addressables have assumptions about where they are in their hierarchy when they are enabled (instantiated), so this is causing a lot of error spam when in Play Mode in editor.
     
    eggsamurai and JesseSTG like this.
  4. xiaoyinan

    xiaoyinan

    Joined:
    Apr 11, 2018
    Posts:
    2
    Any fix plan?
     
    JesseSTG likes this.
  5. Sologamer

    Sologamer

    Joined:
    Feb 15, 2013
    Posts:
    12
    There is also a big issue (1.18.2, 1.18.4) when you have Canvas (UI) objects in Addressables group when in Fast Mode, the instanced copies Unity creates which are not in the hierarchy are then blocking UI input, acting like the UI is active. This also applies for Cinemachine Virtual Camera's
     
    eggsamurai and JesseSTG like this.
  6. jperry_oddgames

    jperry_oddgames

    Joined:
    Sep 18, 2017
    Posts:
    62
    JesseSTG likes this.
  7. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    As @jperryoddgames says we have reverted changes that caused this behaviour.
    The original changes were intended to make AssetDatabase mode work the same as Existing Build/Release. Our implementation of this caused issues that I missed when making the change. After careful consideration these new issues are worse than the original behaviour we were looking to solve, and have not been able to find a reasonably solution to them. From that, the changes will be reverted in the next release 1.18.5 expected shortly.
     
  8. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Thank you. Please be more careful about major changes like this next time.
     
    SevenPointRed and phobos2077 like this.
  9. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    So, how's this going?
     
  10. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    Any update on this, I have been testing the latest alpha 19 and its stuck on the broken version of addressables.
     
  11. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Any update on this?
     
  12. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Reproduces on 1.18.9
     
    phobos2077 likes this.
  13. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    hmmm the original code that caused this should be completely removed.
    Do you have a repro for this and can create a bug report?
     
  14. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    I'll try to make it.
     
  15. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Ok, I've researched a bit, looks like some timings of InstantiateAsync have changed and the order events I receive too and that's why project looks broken like with the previous issue. But I can deal with it. Thanks for the fixes!
     
    phobos2077 likes this.
  16. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Also it would be great if big internal changes would be mentioned in the changelog too.
     
    SevenPointRed likes this.