UnityException: Transform child out of bounds

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

UnityException: Transform child out of bounds
Unity.NetCode.Editor.GhostAuthoringComponentEditor.SyncComponentList (Unity.NetCode.GhostAuthoringComponent self) (at Library/PackageCache/com.unity.netcode@0.6.0-preview.7/Editor/GhostAuthoringComponentEditor.cs:521)
Unity.NetCode.Editor.GhostAuthoringComponentEditor.OnInspectorGUI () (at Library/PackageCache/com.unity.netcode@0.6.0-preview.7/Editor/GhostAuthoringComponentEditor.cs:304)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <0fdaf67e8e744beea25e77915c19f81b>:0)
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)

7069699--840349--ghostAuthoring_exception.PNG

Is this a known limitation on the depth of the hierarchy supported by ghost entities?

1 Like

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.

1 Like

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:

public void SyncComponentList(GhostAuthoringComponent self)
        {
            using (var tempWorld = new World("TempGhostConversion"))
            using (var blobAssetStore = new BlobAssetStore())
            {
                self.ForcePrefabConversion = true;
                var convertedEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(self.gameObject,
                    GameObjectConversionSettings.FromWorld(tempWorld, blobAssetStore));
                self.ForcePrefabConversion = false;

                var newComponents = new List<SerializedComponentData>();
                AddToComponentList(newComponents, tempWorld, convertedEntity, 0, self.gameObject);

                if (tempWorld.EntityManager.HasComponent<LinkedEntityGroup>(convertedEntity))
                {
                    var transformGroup = self.GetComponentsInChildren<Transform>(true);
                    var linkedEntityGroup = tempWorld.EntityManager.GetBuffer<LinkedEntityGroup>(convertedEntity);
                    for (int i = 1; i < linkedEntityGroup.Length; ++i)
                    {
                        AddToComponentList(newComponents, tempWorld, linkedEntityGroup[i].Value, i, transformGroup[i].gameObject);
                    }
                }

                Components = newComponents.ToArray();
            }
        }

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.

1 Like

Is this by design, or will you support it in the future?

It may be extended in the future, but for now this is a limitation we have to enforce for performance reasons.

1 Like

Please Anyone help me to fix this issue i shall be very thankfull.
UnityException: Transform child out of bounds
DetectVehicle.OnTriggerEnter (UnityEngine.Collider coll)

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.