Unity-Technologies/UnityCsReference · error · ArgumentNullException
Parameter prefabAssetGameObject is null
Error message
Parameter prefabAssetGameObject is null
What it means
SavePrefabAsset requires a non-null asset GameObject. The method dereferences the asset immediately (type checks, path lookup), so a null argument throws ArgumentNullException. Note the message refers to 'prefabAssetGameObject' (the internal parameter name) rather than the public 'asset' name.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2018
}
var empty = new GameObject("EmptyPrefab");
bool success;
var assetObject = SaveAsPrefabAsset(empty, path, out success);
Object.DestroyImmediate(empty);
return PrefabUtility.GetPrefabObject(assetObject);
}
public static GameObject SavePrefabAsset(GameObject asset)
{
bool savedSuccesfully;
return SavePrefabAsset(asset, out savedSuccesfully);
}
public static GameObject SavePrefabAsset(GameObject asset, out bool savedSuccessfully)
{
if (asset == null)
throw new ArgumentNullException("Parameter prefabAssetGameObject is null");
// Include model check even though models are also immutable, since we can give a more clear exception message.
if (IsPartOfModelPrefab(asset))
throw new ArgumentException("Can't save a Model Prefab");
if (IsPartOfImmutablePrefab(asset))
throw new ArgumentException("Can't save an immutable Prefab");
string path = AssetDatabase.GetAssetPath(asset);
if (String.IsNullOrEmpty(path))
throw new ArgumentException("Can't save a Prefab instance");
var root = asset.transform.root.gameObject;
if (root != asset)
throw new ArgumentException("GameObject to save Prefab from must be a Prefab root");
return SavePrefabAsset_Internal(root, out savedSuccessfully);
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Null-check the asset before calling.
- Resolve the asset from a known source (AssetDatabase.LoadAssetAtPath) and verify before saving.
- Guard with a clear editor message when the resolved asset is null.
Example fix
// before
PrefabUtility.SavePrefabAsset(asset);
// after
if (asset != null)
PrefabUtility.SavePrefabAsset(asset); Defensive patterns
Strategy: validation
Validate before calling
if (asset == null) return;
Type guard
static bool IsPrefabAsset(GameObject asset) => asset != null;
Prevention
- Null-check the asset before saving.
- Resolve the asset from a known source and verify before calling SavePrefabAsset.
- Show a clear editor message when the resolved asset is null.
When it happens
Trigger: Calling PrefabUtility.SavePrefabAsset(null) or SavePrefabAsset(null, out _); passing a reference that resolved to null.
Common situations: Resolving the prefab asset via a query that returned null (e.g., selection active object was not a prefab); field never initialized before the save call.
Related errors
- Cannot apply added GameObjects. GameObjects array is null.
- Cannot revert added GameObject. GameObject is null.
- guid
- prefabInstance
- Provided GameObject is not a Prefab instance
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/d014c1c246586062.
Report an issue: GitHub.