InstantiateAsync renderer references in array are null

Hello!

If you have a prefab, with a bunch of renderers on, any script attached referencing those renderers in an array will have mostly null entries when using InstantiateAsync. If I loop through said renderers in Start of an instance, only the last reference is intact. Using regular old Instantiate on the same prefab and all the references are intact. In builds only mind you, the editor seems fine.

Unless I’m misunderstanding the resulting GameObject should be analogous with one using normal Instantiate? Considering that the editor works as expected I can only assume it is a bug that only shows up in builds.

Looking at the amount of similar bugs concerning InstantiateAsync being fixed in various minor versions of 2022-3 LTS, don’t get me wrong it’s great they’re getting fixed but, it does feel a bit like there’s some amount of regression testing missing?

I made a bug report with a small repro case, with reference IN-82552. For me it specifically happens in Meta Quest 2 builds. I don’t know about builds for other platforms, I haven’t checked. Not sure if it matters posting about it here too, but I figured it might increase visibility about an easily verifiable bug in core functionality. And its always nice to not feel alone in experiencing a bug so if you’re someone looking for verification that the bug is real, yes you’re not alone :3

Unity got back to me saying this is the same bug and they’re working on it:

I let them know that in contrast with the one they figured it’s a duplicate of, this bug doesn’t happen in play mode, so they reviewed it again and made a separate bug tracker for it which you can track here: Unity Issue Tracker - [Android] Null reference when using InstantiateAsync

Is there any known workarounds for this issue? Just encountered this myself, after trying to figure out why everything was null when I swapped to InstantiateAsync

Probably not! I’m just glad Unity confirmed it on their end, I expect it to be fixed soon. I’ve just temporarily reverted to using Instantiate until then.

Fair enough, in my case, I found a smaller workaround, where I can “re-generate” the arrays for the objects I need in their Start/Awake methods, using GetComponents and GetComponentsInChildren, which has worked out with very little noticeable performance effects.

Can Unity just please prioritize fixing this in a 2022 LTS version already? I naively assumed you would fix it in the next minor release, but it’s literally been 10 versions since I reported this. It can seem minor, like yeah just GetComponent the things you need in Start, but that’s an insane overhead when you have hundreds of objects. We literally have house-rules that you aren’t allowed to do GetComponent stuff in Awake/Start because it creates a framerate hitch when a scene loads and when objects get created.

Also, I’m suspecting this is just a tip of the iceberg type issue, like if this example case is bugged, what else is not deserialized properly when using InstantiateAsync.

Unity pls

Hello again!

Any progress on this? I’ve seen a bunch of other InstantiateAsync bugs being fixed but not this particular one for some reason. Been like half a year now?

Thanks