Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Asset Bundles' started by watsonsong, May 27, 2017.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    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.
     

    Attached Files:

    ZiaYu likes this.
  2. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    BTW, I found the AssetBundle.Unload(true) sometime will cause the same problem even in 5.5.x
     
  3. Reichert

    Reichert

    Unity Technologies

    Joined:
    Jun 20, 2014
    Posts:
    63
    Thank you for reporting this .. we actually found the same problem last week during Hackweek! We're investigating.
     
  4. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Will the next patch version fix this problem?
    I was waiting for it since last week :)
     
  5. Reichert

    Reichert

    Unity Technologies

    Joined:
    Jun 20, 2014
    Posts:
    63
    We are still investigating to find the root issue, and very far from a fix at this point.
     
  6. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    How about this problem, will it be fixed in the patch version of this week?
     
  7. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Hi, Reichert. Is there any conclusion for this issue?
    There still not any mention in 5.6.1p4, is it still in progress?
     
  8. BoboShu

    BoboShu

    Joined:
    Nov 20, 2014
    Posts:
    38
  9. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    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!
     
  10. BoboShu

    BoboShu

    Joined:
    Nov 20, 2014
    Posts:
    38
    please fix it as soon as possible .....i cant build my game on 5.6
     
  11. whitebai

    whitebai

    Joined:
    Dec 12, 2014
    Posts:
    2
    our project use 5.5.x,if the problem will not fix,I don't think we can upgrade to 5.6.x
     
  12. xvly

    xvly

    Joined:
    Jan 26, 2016
    Posts:
    2
    I met the same problem, please fix it!!!
     
  13. ZiaYu

    ZiaYu

    Joined:
    May 27, 2017
    Posts:
    2
    I got the same bug!It's deadly for our project!!please fix it soon..
     
  14. Reichert

    Reichert

    Unity Technologies

    Joined:
    Jun 20, 2014
    Posts:
    63
    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.
     
  15. PaulBurslem

    PaulBurslem

    Unity Technologies

    Joined:
    Oct 7, 2016
    Posts:
    79
    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.
     
  16. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Thanks for your replay. Does it mean I can check all my prefab by this way?
    Code (CSharp):
    1.  
    2. private void CheckProperty(Component component, SerializedProperty sp)
    3. {
    4.     if (sp.propertyType == SerializedPropertyType.ObjectReference)
    5.     {
    6.         if (sp.objectReferenceValue != null)
    7.         {
    8.             var prefabType = PrefabUtility.GetPrefabType(
    9.                 sp.objectReferenceValue);
    10.             if (prefabType == PrefabType.Prefab ||
    11.                 prefabType == PrefabType.ModelPrefab)
    12.             {
    13.                 var go = sp.objectReferenceValue as GameObject;
    14.                 if (go != null)
    15.                 {
    16.                     var root = PrefabUtility.FindPrefabRoot(go);
    17.                     var selfRoot = PrefabUtility.FindPrefabRoot(component.gameObject);
    18.                     if (selfRoot != root && root != go)
    19.                     {
    20.                         Debug.LogWarningFormat(
    21.                             "The GameObject <b><color=orange>{0}</color></b> reference a no-root prefab reference at " +
    22.                             "component: <b><color=orange>{1}</color></b>'s property: <b><color=orange>{2}</color></b>.",
    23.                             component.name,
    24.                             component.GetType().Name,
    25.                             ObjectNames.NicifyVariableName(sp.name));
    26.                     }
    27.                 }
    28.                 else
    29.                 {
    30.                     var c = sp.objectReferenceValue as Component;
    31.                     if (c != null)
    32.                     {
    33.                         var root = PrefabUtility.FindPrefabRoot(c.gameObject);
    34.                         var selfRoot = PrefabUtility.FindPrefabRoot(component.gameObject);
    35.                         if (selfRoot != root && root != c.gameObject)
    36.                         {
    37.                             Debug.LogWarningFormat(
    38.                                 "The GameObject <b><color=orange>{0}</color></b> reference a no-root prefab reference at " +
    39.                                 "component: <b><color=orange>{1}</color></b>'s property: <b><color=orange>{2}</color></b>.",
    40.                                 component.name,
    41.                                 component.GetType().Name,
    42.                                 ObjectNames.NicifyVariableName(sp.name));
    43.                         }
    44.                     }
    45.                 }
    46.             }
    47.         }
    48.     }
    49. }
    50.  
     
  17. PaulBurslem

    PaulBurslem

    Unity Technologies

    Joined:
    Oct 7, 2016
    Posts:
    79
    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.
     
  18. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    @PauBurslem, this bug is still there. I am using Unity 2017.1.3p2, still met this bug.