Load assetbundle will cause the c# virtual machine restart in 5.6.x

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.

3085476--232441--AssetBundleTest1.png
3085476--232442--AssetBundleTest2.png

1 Like

BTW, I found the AssetBundle.Unload(true) sometime will cause the same problem even in 5.5.x

Thank you for reporting this … we actually found the same problem last week during Hackweek! We’re investigating.

Will the next patch version fix this problem?
I was waiting for it since last week :slight_smile:

We are still investigating to find the root issue, and very far from a fix at this point.

How about this problem, will it be fixed in the patch version of this week?

Hi, Reichert. Is there any conclusion for this issue?
There still not any mention in 5.6.1p4, is it still in progress?

!!

I am testing on Unity5.6.2p1, and this problem is still occur on Android!!!

I am really worry about this problem, we can not ship our game!

please fix it as soon as possible …i cant build my game on 5.6

our project use 5.5.x,if the problem will not fix,I don’t think we can upgrade to 5.6.x

I met the same problem, please fix it!!!

I got the same bug!It’s deadly for our project!!please fix it soon…

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.

Thanks for your replay. Does it mean I can check all my prefab by this way?

private void CheckProperty(Component component, SerializedProperty sp)
{
    if (sp.propertyType == SerializedPropertyType.ObjectReference)
    {
        if (sp.objectReferenceValue != null)
        {
            var prefabType = PrefabUtility.GetPrefabType(
                sp.objectReferenceValue);
            if (prefabType == PrefabType.Prefab ||
                prefabType == PrefabType.ModelPrefab)
            {
                var go = sp.objectReferenceValue as GameObject;
                if (go != null)
                {
                    var root = PrefabUtility.FindPrefabRoot(go);
                    var selfRoot = PrefabUtility.FindPrefabRoot(component.gameObject);
                    if (selfRoot != root && root != go)
                    {
                        Debug.LogWarningFormat(
                            "The GameObject <b><color=orange>{0}</color></b> reference a no-root prefab reference at " +
                            "component: <b><color=orange>{1}</color></b>'s property: <b><color=orange>{2}</color></b>.",
                            component.name,
                            component.GetType().Name,
                            ObjectNames.NicifyVariableName(sp.name));
                    }
                }
                else
                {
                    var c = sp.objectReferenceValue as Component;
                    if (c != null)
                    {
                        var root = PrefabUtility.FindPrefabRoot(c.gameObject);
                        var selfRoot = PrefabUtility.FindPrefabRoot(component.gameObject);
                        if (selfRoot != root && root != c.gameObject)
                        {
                            Debug.LogWarningFormat(
                                "The GameObject <b><color=orange>{0}</color></b> reference a no-root prefab reference at " +
                                "component: <b><color=orange>{1}</color></b>'s property: <b><color=orange>{2}</color></b>.",
                                component.name,
                                component.GetType().Name,
                                ObjectNames.NicifyVariableName(sp.name));
                        }
                    }
                }
            }
        }
    }
}

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.

@PauBurslem, this bug is still there. I am using Unity 2017.1.3p2, still met this bug.