When I upgrade to Unity 5.6.x, I met a problem.
I have an asset bundle with a prefab, and it dependent on another assetbundle which contain another prefab.
If I load this assetbunlde and load this prefab, will cause the c# virtual machine restart.
It means all static variable will reset, all static constructor will re-invoked, and all the function marked as InitializeOnLoad will re-invoked.
The code and test as below:
When I downgrade into Unity5.5.x, everything is OK.
I think it may be a bug for Unity 5.6.x.
Hey guys, sorry for the delay in getting back to you on this. Good news - we found the problem. The engineer on our team that is working on a fix will post here with more details soon.
Hi, I am working on the fix for this. During a validation step for MonoBehavior, the editor detects missing script reference and tries to fix it, causing the domain reload. This validation only happens in the editor so a domain reload in the player is not possible. This validation was supposed to only happen on script import, but can run when a MonoBehavior is loaded from an AssetBundle. The root issue is that a script on a prefab references a child object of another prefab that is not in the same bundle. The new Asset Bundle Pipeline will not have this issue, but changing the behavior of the current AB system to account for a child reference in another bundle is a risky change. The fix for the domain reload will prevent the validation step from triggering a domain reload, but the script references will still be broken. A workaround that you can use is to ensure that there is a reference to the prefab root from the bundle that has a reference to the prefab child.
Referencing a child of another prefab is OK as long as it is in the same asset bundle (or in resources together) or as long as there is a reference to the parent prefab of the thing that is referenced. Your script will warn about potential issues but will probably show a lot of false positives.