Unity-Technologies/UnityCsReference · error · ArgumentNullException
settings
Error message
settings
What it means
Thrown by ReplacePrefabAssetOfPrefabInstances (the overload taking PrefabReplacingSettings) when the settings parameter is null. PrefabReplacingSettings controls how overrides and object references are handled during the batch replace; a null value is not permitted — the simpler overload constructs a default PrefabReplacingSettings internally.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2289
throw new InvalidOperationException(string.Format($"Cannot replace the Prefab instance when it has a missing script. GameObject '{gameObjectsWithInvalidScript[0].name}' has a missing script. Use InteractionMode.AutomatedAction to force the replace."));
}
}
public static void ReplacePrefabAssetOfPrefabInstances(GameObject[] prefabInstanceRoots, GameObject prefabAssetRoot, InteractionMode mode)
{
ReplacePrefabAssetOfPrefabInstances(prefabInstanceRoots, prefabAssetRoot, new PrefabReplacingSettings(), mode);
}
public static void ReplacePrefabAssetOfPrefabInstances(GameObject[] prefabInstanceRoots, GameObject prefabAssetRoot, PrefabReplacingSettings settings, InteractionMode mode)
{
if (prefabInstanceRoots == null)
throw new ArgumentNullException(nameof(prefabInstanceRoots));
if (prefabInstanceRoots.Length == 0)
throw new ArgumentException(nameof(prefabInstanceRoots) + " has no objects");
if (settings == null)
throw new ArgumentNullException(nameof(settings));
ThrowIfInvalidAssetForReplacePrefabInstance(prefabAssetRoot, mode);
foreach (var go in prefabInstanceRoots)
ThrowIfInvalidArgumentsForReplacePrefabInstance(go, prefabAssetRoot, false, mode);
foreach (var go in prefabInstanceRoots)
ReplacePrefabAssetOfPrefabInstance_NoInputValidation(go, prefabAssetRoot, settings, mode);
EditorUtility.ForceRebuildInspectors();
}
public static void ReplacePrefabAssetOfPrefabInstance(GameObject prefabInstanceRoot, GameObject prefabAssetRoot, InteractionMode mode)
{
ReplacePrefabAssetOfPrefabInstance(prefabInstanceRoot, prefabAssetRoot, new PrefabReplacingSettings(), mode);
}
public static void ReplacePrefabAssetOfPrefabInstance(GameObject prefabInstanceRoot, GameObject prefabAssetRoot, PrefabReplacingSettings settings, InteractionMode mode)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Pass new PrefabReplacingSettings() as the default when you don't need custom settings.
- Use the 3-argument overload ReplacePrefabAssetOfPrefabInstances(roots, asset, mode) which constructs default settings for you.
- Null-check settings and substitute a default before calling.
Example fix
// before PrefabUtility.ReplacePrefabAssetOfPrefabInstances(roots, asset, settings, mode); // settings could be null // after PrefabUtility.ReplacePrefabAssetOfPrefabInstances(roots, asset, settings ?? new PrefabReplacingSettings(), mode);
Defensive patterns
Strategy: validation
Validate before calling
var effectiveSettings = settings ?? new PrefabReplacingSettings(); PrefabUtility.ReplacePrefabAssetOfPrefabInstances(prefabInstanceRoots, prefabAssetRoot, effectiveSettings, mode);
Prevention
- Default optional settings parameters to new PrefabReplacingSettings() in wrapper methods.
- Use the simpler 3-argument overload when default settings suffice.
When it happens
Trigger: Calling ReplacePrefabAssetOfPrefabInstances(roots, asset, null, mode) — e.g. a settings object that was conditionally created but the condition was false.
Common situations: Serialization/deserialization round-trip that produced null. Optional settings parameter in a wrapper method that wasn't defaulted. Code that intended to call the simpler overload but passed null explicitly.
Related errors
- prefabInstanceRoots
- plainGameObject
- The path is null
- Input '{0}' is not a Prefab instance, for plain GameObjects
- Input instance is not an outermost Prefab instance root. Inp
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/ed6b6f50a981d4b4.
Report an issue: GitHub.