Unity-Technologies/UnityCsReference · error · ArgumentException
Array is invalid.
Error message
Array is invalid.
What it means
Thrown by HasSameAssetPath when the input infos array is null or has zero elements. The method cannot determine a common asset path without at least one entry, so it rejects the input as invalid rather than returning a misleading result.
Source
Thrown at Editor/Mono/GUI/TargetChoiceHandler.cs:151
}
if (!PrefabUtility.HasSameParent(gameObjects))
throw new ArgumentException(nameof(gameObjects), "ApplyPrefabAddedGameObjects requires that GameObjects share the same parent.");
if (!HasSameAssetPath(infos))
throw new ArgumentException(nameof(infos), "ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path.");
if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(infos[0].assetPath, PrefabUtility.SaveVerb.Apply))
return;
PrefabUtility.ApplyAddedGameObjects(gameObjects, infos[0].assetPath, InteractionMode.UserAction);
EditorUtility.ForceRebuildInspectors();
}
internal static bool HasSameAssetPath(ObjectInstanceAndSourcePathInfo[] infos)
{
if (infos == null || infos.Length == 0)
throw new ArgumentException(nameof(infos), "Array is invalid.");
string assetPath = infos[0].assetPath;
for (int i = 1; i < infos.Length; i++)
{
if (assetPath != infos[i].assetPath)
return false;
}
return true;
}
internal static void RevertPrefabAddedGameObjects(object userData)
{
GameObject[] gameObjects = (GameObject[])userData;
foreach (GameObject go in gameObjects)
PrefabUtility.RevertAddedGameObject(go, InteractionMode.UserAction);
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Guard callers: return early (no-op) when the selection is empty or null before reaching HasSameAssetPath.
- Initialize infos from a validated non-empty selection.
- Assert the count > 0 at the UI boundary and disable the apply action for empty selections.
Example fix
// before
if (!HasSameAssetPath(infos)) { /* ... */ } // infos may be empty
// after
if (infos == null || infos.Length == 0) return;
if (!HasSameAssetPath(infos)) { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
if (infos == null || infos.Length == 0) { /* skip, nothing to do */ return; } Prevention
- Short-circuit empty selections before invoking apply/validation.
- Disable Apply when selection count is zero.
- Treat null/empty as a no-op, not an error, at the UI boundary.
When it happens
Trigger: Calling HasSameAssetPath with a null array or an empty ObjectInstanceAndSourcePathInfo[]; an upstream selection that produced no items being forwarded unfiltered.
Common situations: Empty user selection passed through to apply logic; a filtering step that removed all entries but did not short-circuit before validation.
Related errors
- ApplyPrefabAddedGameObjects requires that GameObjects share
- ApplyPrefabAddedGameObjects requires that GameObjects share
- root
- The Prefab you want to instantiate is null.
- The source path cannot be empty.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/8866279d07d494de.
Report an issue: GitHub.