Unity-Technologies/UnityCsReference · error · ArgumentNullException

prefabAsset

Error message

prefabAsset

What it means

Thrown by GetVariantParentGUID(GameObject prefabAsset) when the `prefabAsset` argument is null. The method reads the GUID of the prefab a variant was created from, requiring a non-null prefab asset. Uses nameof(prefabAsset) so the parameter name is the message.

Source

Thrown at Editor/Mono/Prefabs/PrefabUtility.bindings.cs:446

        [NativeMethod("PrefabUtilityBindings::IsDefaultOverridePropertyPath", IsFreeFunction = true)]
        extern internal static bool IsDefaultOverridePropertyPath(string propertyPath);

        [FreeFunction]
        extern internal static bool CheckIfAddingPrefabWouldResultInCyclicNesting(Object prefabAssetThatIsAddedTo, Object prefabAssetThatWillBeAdded);

        [FreeFunction]
        extern internal static bool WasCreatedAsPrefabInstancePlaceholderObject(Object componentOrGameObject);

        [FreeFunction]
        extern internal static void ShowCyclicNestingWarningDialog();

        [NativeMethod("PrefabUtilityBindings::GetVariantParentGUID_Internal", IsFreeFunction = true, ThrowsException = true)]
        extern internal static string GetVariantParentGUID(EntityId prefabAssetInstanceID);

        internal static string GetVariantParentGUID(GameObject prefabAsset)
        {
            if (prefabAsset == null)
                throw new ArgumentNullException(nameof(prefabAsset));
            return GetVariantParentGUID(prefabAsset.GetEntityId());
        }

        [FreeFunction]
        extern internal static bool IsPathInStreamingAssets(string path);

        [StaticAccessor("PrefabUtilityBindings", StaticAccessorType.DoubleColon)]
        [NativeMethod(ThrowsException = true)]
        extern private static bool ApplyObjectOverride([NotNull] Object componentOrGameObject, string assetPath);

        [StaticAccessor("PrefabUtilityBindings", StaticAccessorType.DoubleColon)]
        [NativeMethod(ThrowsException = true)]
        extern private static bool ApplyObjectOverrideWithoutUndo([NotNull] Object componentOrGameObject, string assetPath);

        [StaticAccessor("PrefabUtilityBindings", StaticAccessorType.DoubleColon)]
        [NativeMethod(ThrowsException = true)]
        extern private static bool ApplyPropertyOverride([NotNull] Object componentOrGameObject, string propertyPath, string assetPath);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Pass a non-null prefab asset GameObject.
  2. Null-check prefabAsset before calling and handle the missing case explicitly.
  3. Validate via PrefabUtility.IsPartOfPrefabAsset when you also need to ensure it is a prefab.

Example fix

// before
var guid = PrefabUtility.GetVariantParentGUID(maybeNullAsset);

// after
if (prefabAsset == null) return string.Empty;
var guid = PrefabUtility.GetVariantParentGUID(prefabAsset);
Defensive patterns

Strategy: validation

Validate before calling

if (prefabAsset == null)
    return string.Empty; // or throw your own descriptive error

Type guard

static bool IsPrefabAssetForVariant(GameObject g) => g != null && PrefabUtility.IsPartOfPrefabAsset(g);

Prevention

When it happens

Trigger: Calling PrefabUtility.GetVariantParentGUID(null), or passing a reference resolved from a failed asset lookup, an unassigned serialized field, or a destroyed object.

Common situations: Editor inspectors that query variant info but have no asset assigned. Scripts iterating assets where some entries failed to load. Code paths that assume a Selection.activeObject is a prefab when it is null.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/379e5aafce1fa01c. Report an issue: GitHub.