Unity-Technologies/UnityCsReference · error · ArgumentException
plainGameObjects has no objects
Error message
plainGameObjects has no objects
What it means
PrefabUtility.ConvertToPrefabInstances throws an ArgumentException when plainGameObjects is an empty array. The API requires at least one GameObject to operate on; an empty array is meaningless for prefab conversion.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2394
}
}
public static void ConvertToPrefabInstance(GameObject plainGameObject, GameObject prefabAssetRoot, ConvertToPrefabInstanceSettings settings, InteractionMode mode)
{
ThrowIfInvalidArgumentsForConvertToPrefabInstance(plainGameObject, prefabAssetRoot, true, mode);
ConvertToPrefabInstance_NoInputValidation(plainGameObject, prefabAssetRoot, settings, mode);
EditorUtility.ForceRebuildInspectors();
}
public static void ConvertToPrefabInstances(GameObject[] plainGameObjects, GameObject prefabAssetRoot, ConvertToPrefabInstanceSettings settings, InteractionMode mode)
{
if (plainGameObjects == null)
throw new ArgumentNullException(nameof(plainGameObjects));
if (plainGameObjects.Length == 0)
throw new ArgumentException(nameof(plainGameObjects) + " has no objects");
foreach(var go in plainGameObjects)
if (go == null)
throw new ArgumentException(nameof(plainGameObjects) + " has a null GameObject");
if (settings == null)
throw new ArgumentNullException(nameof(settings));
ThrowIfInvalidAssetForReplacePrefabInstance(prefabAssetRoot, mode);
var topLevelGameObjects = GetTopLevelGameObjects(plainGameObjects);
foreach (var go in topLevelGameObjects)
ThrowIfInvalidArgumentsForConvertToPrefabInstance(go, prefabAssetRoot, false, mode);
foreach (var go in topLevelGameObjects)
ConvertToPrefabInstance_NoInputValidation(go, prefabAssetRoot, settings, mode);
EditorUtility.ForceRebuildInspectors();View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check plainGameObjects.Length > 0 before calling the API.
- Guard with early return: if (gos.Length == 0) return;
- Use Selection.gameObjects filtered to valid candidates and verify count before proceeding.
Example fix
// before
PrefabUtility.ConvertToPrefabInstances(new GameObject[0], root, settings, InteractionMode.AutomatedAction);
// after
if (gos != null && gos.Length > 0)
PrefabUtility.ConvertToPrefabInstances(gos, root, settings, InteractionMode.AutomatedAction); Defensive patterns
Strategy: validation
Validate before calling
if (plainGameObjects == null || plainGameObjects.Length == 0)
return;
PrefabUtility.ConvertToPrefabInstances(plainGameObjects, root, settings, mode); Type guard
static bool HasObjects(GameObject[] arr) => arr != null && arr.Length > 0;
Prevention
- Check Length before calling collection-based Unity APIs
- Guard bulk operations with early-return on empty input
- Log when input is unexpectedly empty to catch upstream bugs
When it happens
Trigger: Calling ConvertToPrefabInstances with a zero-length GameObject[] (e.g., new GameObject[0], Array.Empty<GameObject>(), or an empty selection).
Common situations: User selected nothing in the Hierarchy, a filter returned zero results, or a bulk-operation pipeline ran with an empty input set.
Related errors
- UnpackPrefabInstance must be called with a Prefab instance.
- UnpackPrefabInstance must be called with a root Prefab insta
- Scene path cannot be null or empty.
- Path {scenePath} is not a scene path. Must end with .unity e
- No material targets provided
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/78d080a6937bace4.
Report an issue: GitHub.