Unity-Technologies/UnityCsReference · error · ArgumentNullException
The inputObject is null
Error message
The inputObject is null
What it means
PrefabUtility.CreateVariant is an internal method that creates a prefab variant from an existing prefab asset root. The first precondition checks that assetRoot is not null and throws ArgumentNullException with the message 'The inputObject is null'. This is the entry guard before subsequent checks verify the object is a prefab asset, is a prefab root, and that the target path is valid.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.bindings.cs:228
// Resets the properties of all objects in the prefab, including child game objects and components that were added to the prefab instance
[Obsolete("Use the overload that takes an InteractionMode parameter.")]
[FreeFunction]
extern public static bool RevertPrefabInstance([NotNull] GameObject go);
// Resets the properties of all objects in the prefab, including child game objects and components that were added to the prefab instance
[NativeMethod("RevertPrefabInstance", IsFreeFunction = true)]
extern private static bool RevertPrefabInstance_Internal([NotNull] GameObject go);
// Helper function to find the prefab root of an object
[FreeFunction]
[Obsolete("Use GetOutermostPrefabInstanceRoot if source is a Prefab instance or source.transform.root.gameObject if source is a Prefab Asset object.")]
extern public static GameObject FindPrefabRoot([NotNull] GameObject source);
internal static GameObject CreateVariant(GameObject assetRoot, string path)
{
if (assetRoot == null)
throw new ArgumentNullException("The inputObject is null");
if (!IsPartOfPrefabAsset(assetRoot))
throw new ArgumentException("Given input object is not a prefab asset");
if (assetRoot.transform.root.gameObject != assetRoot)
throw new ArgumentException("Object to create variant from has to be a Prefab root");
if (path == null)
throw new ArgumentNullException("The path is null");
var assetRootObjectPath = AssetDatabase.GetAssetPath(assetRoot);
if (Paths.AreEqual(path, assetRootObjectPath, true))
throw new ArgumentException("Creating a variant of an object into the source file of the input object is not allowed");
if (!Paths.IsValidAssetPath(path, ".prefab"))
throw new ArgumentException("Given path is not valid: '" + path + "'");
return CreateVariant_Internal(assetRoot, path);View on GitHub (pinned to 225b0fbdb5)
Solutions
- Null-check assetRoot before calling CreateVariant
- Trace the source: verify Selection.activeGameObject, GameObject.Find, or the traversal logic returned a valid object
- Use PrefabUtility.GetRootGameObjectAsAssetRoot or similar to get a guaranteed non-null root
Example fix
// before
var variant = PrefabUtility.CreateVariant(sourcePrefab, "Assets/NewVariant.prefab");
// after
if (sourcePrefab == null)
{
Debug.LogError("Source prefab is null.");
return;
}
var variant = PrefabUtility.CreateVariant(sourcePrefab, "Assets/NewVariant.prefab"); Defensive patterns
Strategy: validation
Validate before calling
if (assetRoot == null)
{
Debug.LogError("Cannot create variant: source prefab is null.");
return;
}
// Safe to call CreateVariant(assetRoot, path) Type guard
static bool IsValidVariantSource(GameObject go) =>
go != null && PrefabUtility.IsPartOfPrefabAsset(go) && go.transform.root.gameObject == go; Try / catch
try { var variant = PrefabUtility.CreateVariant(assetRoot, path); }
catch (ArgumentNullException ex) when (ex.Message == "The inputObject is null")
{ Debug.LogError("CreateVariant: assetRoot was null."); } Prevention
- Null-check all GameObject arguments before calling CreateVariant
- Validate Selection.activeGameObject and traversal results before using them as prefab sources
- Log the source object's name and type when debugging null prefab references
When it happens
Trigger: Calling PrefabUtility.CreateVariant(null, path) or passing a variable that resolved to null (e.g., a failed Selection.activeGameObject, a destroyed reference, or a GetComponent that returned null).
Common situations: Editor tools that create prefab variants from a user selection where nothing is selected. Code that finds a prefab root via traversal but the traversal returns null on edge cases. Generic automation that processes multiple objects where some are null.
Related errors
- guid
- prefabInstance
- Given input object is not a prefab asset
- Object to create variant from has to be a Prefab root
- Provided GameObject is not a Prefab instance
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/01fe342683d41be4.
Report an issue: GitHub.