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

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:

  • Open the attached SampleScene
  • Enter play mode
  • Exit play mode
  • Look at the console. You will see 8 log entries which should look something like this:
SpawnedObject.Awake(<instance ID>)
SpawnedObject.OnEnable(<instance ID>)
SpawnedObject.Awake(<different instance ID>)
SpawnedObject.OnEnable(<different instance ID>)
SpawnedObject.Start(<different instance ID>)
SpawnedObject.OnDestroy(<instance ID>)
SpawnedObject.OnDisable(<different instance ID>)
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.

7138700–853709–Addressables Bug.zip (22.4 KB)

1 Like

I’ve also posted a bug report related to the issue here:
https://fogbugz.unity3d.com/default.asp?1336143_nnuuqh6ge7hrp8p2

2 Likes

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.

2 Likes

Any fix plan?

1 Like

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

2 Likes

@JesseSTG_1 @stephen_mor @xiaoyinan @Sologamer
It looks like the bugs mentioned in this thread are also being discussed in the thread over at

Per unity’s response there, it looks like they’ll be reverting the breaking change for 1.18.5

1 Like

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.

4 Likes

Thank you. Please be more careful about major changes like this next time.

2 Likes

So, how’s this going?

Any update on this, I have been testing the latest alpha 19 and its stuck on the broken version of addressables.

Any update on this?

Reproduces on 1.18.9

1 Like

hmmm the original code that caused this should be completely removed.
Do you have a repro for this and can create a bug report?

I’ll try to make it.

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!

1 Like

Also it would be great if big internal changes would be mentioned in the changelog too.

1 Like