Search Unity

Bug UnityException: Transform child out of bounds

Discussion in 'NetCode for ECS' started by Occuros, Apr 23, 2021.

  1. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    300
    When Creating a Ghost (Gameobject with GhostAuthoringComponent), and the number of children is deeper then 1, I get the following exception:


    Code (CSharp):
    1. UnityException: Transform child out of bounds
    2. Unity.NetCode.Editor.GhostAuthoringComponentEditor.SyncComponentList (Unity.NetCode.GhostAuthoringComponent self) (at Library/PackageCache/com.unity.netcode@0.6.0-preview.7/Editor/GhostAuthoringComponentEditor.cs:521)
    3. Unity.NetCode.Editor.GhostAuthoringComponentEditor.OnInspectorGUI () (at Library/PackageCache/com.unity.netcode@0.6.0-preview.7/Editor/GhostAuthoringComponentEditor.cs:304)
    4. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <0fdaf67e8e744beea25e77915c19f81b>:0)
    5. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    Having one child-evel works normally, but as soon as I add any child inside a child entity this exception is thrown.
    (when clicking update component list)

    ghostAuthoring_exception.PNG

    Is this a known limitation on the depth of the hierarchy supported by ghost entities?
     
    Lukas_Kastern likes this.
  2. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    I don't know if the limitation is intended, but I found that I am only able to have a child depth of one when using GhostAuthoringComponent.
     
    Lukas_Kastern likes this.
  3. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    If you're down to modifying the Netcode package, replacing SyncComponentList method in the GhostAuthoringComponentEditor script (around line 521) with the following code should fix the issue:
    Code (CSharp):
    1. public void SyncComponentList(GhostAuthoringComponent self)
    2.         {
    3.             using (var tempWorld = new World("TempGhostConversion"))
    4.             using (var blobAssetStore = new BlobAssetStore())
    5.             {
    6.                 self.ForcePrefabConversion = true;
    7.                 var convertedEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(self.gameObject,
    8.                     GameObjectConversionSettings.FromWorld(tempWorld, blobAssetStore));
    9.                 self.ForcePrefabConversion = false;
    10.  
    11.                 var newComponents = new List<SerializedComponentData>();
    12.                 AddToComponentList(newComponents, tempWorld, convertedEntity, 0, self.gameObject);
    13.  
    14.                 if (tempWorld.EntityManager.HasComponent<LinkedEntityGroup>(convertedEntity))
    15.                 {
    16.                     var transformGroup = self.GetComponentsInChildren<Transform>(true);
    17.                     var linkedEntityGroup = tempWorld.EntityManager.GetBuffer<LinkedEntityGroup>(convertedEntity);
    18.                     for (int i = 1; i < linkedEntityGroup.Length; ++i)
    19.                     {
    20.                         AddToComponentList(newComponents, tempWorld, linkedEntityGroup[i].Value, i, transformGroup[i].gameObject);
    21.                     }
    22.                 }
    23.  
    24.                 Components = newComponents.ToArray();
    25.             }
    26.         }
     
  4. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    896
    In general you can have complex hierarchy BUT the replicated components must be only on the root or 1st children level.
    We don't support having GhostComponent on child objects for deeper hierarchy level. Note that transforms are also not replicated by default for child entities and should not constitute a problem.

    There is a known issue (fixed in later NetCode, that should be out soon) that happen if you prefab presents components that generate during conversion multiple entities for the same game object.
    On example of them is the MeshRenderer when multiple material (or some configuration for lighting probe) are present. In that case, due to the way the HybridRenderer works, multiple entities are created, one for each material, and the SyncComponentList will crash, trying to accessing an child out of bound.
     
    Occuros likes this.
  5. ChrisPie

    ChrisPie

    Joined:
    Mar 5, 2015
    Posts:
    31
    Is this by design, or will you support it in the future?
     
  6. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    896
    It may be extended in the future, but for now this is a limitation we have to enforce for performance reasons.
     
    ChrisPie likes this.
  7. YASIR_167008

    YASIR_167008

    Joined:
    Mar 11, 2022
    Posts:
    1
    Please Anyone help me to fix this issue i shall be very thankfull.
    UnityException: Transform child out of bounds
    DetectVehicle.OnTriggerEnter (UnityEngine.Collider coll)
     
  8. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    896
    The original issue should be already fixed in latest 0.5 and 0.51.
    If you are trying to have replicated component in the second level of the hierarchy, it will not replicated but should not crash,
    I really need more details to help you out here.