Unity-Technologies/UnityCsReference · error · ArgumentNullException
instanceRoot
Error message
instanceRoot
What it means
PrefabUtility.UnpackPrefabInstance throws an ArgumentNullException when instanceRoot is null. This method unpacks a prefab instance back into regular GameObjects and requires the root GameObject of the prefab instance.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2765
}
[RequiredByNativeCode]
internal static void Internal_CallPrefabInstanceReverted(GameObject instanceRoot)
{
Assert.IsNotNull(instanceRoot);
prefabInstanceReverted?.Invoke(instanceRoot);
}
[AutoStaticsCleanupOnCodeReload]
public static event Action<GameObject, PrefabUnpackMode> prefabInstanceUnpacking;
[AutoStaticsCleanupOnCodeReload]
public static event Action<GameObject, PrefabUnpackMode> prefabInstanceUnpacked;
public static void UnpackPrefabInstance(GameObject instanceRoot, PrefabUnpackMode unpackMode, InteractionMode action)
{
if (instanceRoot == null)
throw new ArgumentNullException(nameof(instanceRoot));
if (!IsPartOfNonAssetPrefabInstance(instanceRoot))
throw new ArgumentException("UnpackPrefabInstance must be called with a Prefab instance.");
if (!IsOutermostPrefabInstanceRoot(instanceRoot))
throw new ArgumentException("UnpackPrefabInstance must be called with a root Prefab instance GameObject.");
if (action == InteractionMode.UserAction)
{
var undoActionName = "Unpack Prefab instance";
Undo.RegisterFullObjectHierarchyUndo(instanceRoot, undoActionName);
var newInstanceRoots = UnpackPrefabInstanceAndReturnNewOutermostRoots(instanceRoot, unpackMode);
foreach (var newInstanceRoot in newInstanceRoots)
{
var prefabInstance = PrefabUtility.GetPrefabInstanceHandle(newInstanceRoot);
if (prefabInstance)
{
Undo.RegisterCreatedObjectUndo(prefabInstance, undoActionName);View on GitHub (pinned to 225b0fbdb5)
Solutions
- Null-check instanceRoot before calling.
- Verify the GameObject reference is valid using Unity's null comparison (handles destroyed objects).
- Trace the source of instanceRoot to ensure it comes from a valid prefab instance lookup.
Example fix
// before
PrefabUtility.UnpackPrefabInstance(maybeNullGo, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);
// after
if (instanceRoot != null)
PrefabUtility.UnpackPrefabInstance(instanceRoot, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction); Defensive patterns
Strategy: validation
Validate before calling
if (instanceRoot != null)
PrefabUtility.UnpackPrefabInstance(instanceRoot, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction); Type guard
static bool IsValidInstanceRoot(GameObject go) => go != null;
Prevention
- Check instanceRoot != null (Unity null check) before unpack
- Trace the source of instanceRoot to ensure valid assignment
- Use GetOutermostInstanceRoot result only after null check
When it happens
Trigger: Calling PrefabUtility.UnpackPrefabInstance(null, unpackMode, action) where the first argument is null.
Common situations: Passing a destroyed GameObject, a reference that was set to null by a previous operation, or a field populated from a failed lookup (e.g., GetPrefabInstanceHandle returned null).
Related errors
- plainGameObjects
- GameObject is null.
- Prefab Asset path is null or empty
- plainGameObjects has no objects
- plainGameObjects has a null GameObject
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/7583f2024baff562.
Report an issue: GitHub.