Unity-Technologies/UnityCsReference · error · ArgumentException
Object is a parentless root.
Error message
Object is a parentless root.
What it means
HasSameParent throws when the first element has no parent transform — i.e. it is a root GameObject. The helper needs non-root objects to obtain a baseline parent for comparison, and added overrides are by definition not roots, so a root in this position is invalid.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:1740
action,
startTime,
false
);
}
PrefabUtility.Internal_CallPrefabInstanceApplied(instanceRoot);
EditorUtility.ForceRebuildInspectors();
}
internal static bool HasSameParent(GameObject[] gameObjects)
{
if (gameObjects == null || gameObjects.Length == 0 || gameObjects[0] == null)
throw new ArgumentException(nameof(gameObjects), "Array is invalid.");
Transform goParent = gameObjects[0].transform.parent;
if (goParent == null)
throw new ArgumentException(nameof(goParent), "Object is a parentless root.");
foreach (GameObject go in gameObjects)
{
if (go.transform.parent != goParent)
return false;
}
return true;
}
private static void RemoveRemovedGameObjectOverride(Object instanceObject, GameObject assetGameObject)
{
var removedGameObjects = PrefabUtility.GetRemovedGameObjects(instanceObject);
int index = -1;
for (int i = 0; i < removedGameObjects.Length; i++)
{
//Walk the inheritance chain as you can give the base of a variant as the source asset
if (IsPrefabInstanceObjectOf(removedGameObjects[i], assetGameObject))View on GitHub (pinned to 225b0fbdb5)
Solutions
- Exclude root objects from the array; added overrides are never roots, so filter g.transform.parent != null.
- Verify g.transform.parent != null before adding any object to the apply batch.
- Start selection collection from children of the instance root, not the root itself.
Example fix
// before
var batch = selection.ToArray();
PrefabUtility.ApplyAddedGameObjects(batch, path, mode);
// after
var batch = selection.Where(g => g != null && g.transform.parent != null).ToArray();
if (batch.Length > 0)
PrefabUtility.ApplyAddedGameObjects(batch, path, mode); Defensive patterns
Strategy: validation
Validate before calling
if (gameObjects == null || gameObjects.Length == 0) return false; if (gameObjects[0] == null || gameObjects[0].transform.parent == null) return false;
Type guard
static bool FirstElementHasParent(GameObject[] gos) =>
gos != null && gos.Length > 0 && gos[0] != null
&& gos[0].transform.parent != null; Prevention
- Exclude root objects from apply batches; added overrides are never roots.
- Start selection from children of the instance root, never the root itself.
- Verify g.transform.parent != null for every candidate before batching.
When it happens
Trigger: The first element of the array is a scene root or prefab instance root with transform.parent == null.
Common situations: Including the prefab instance root or a top-level scene object in a batch intended for added-override operations; selection logic that starts from a root.
Related errors
- guid
- prefabInstance
- Provided GameObject is not a Prefab instance
- The inputObject is null
- Given input object is not a prefab asset
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/9e9381957bf1eb0a.
Report an issue: GitHub.