{"record":{"id":"fdc0e888a6894a8b","repo":"Unity-Technologies/UnityCsReference","slug":"the-path-is-null","errorCode":null,"errorMessage":"The path is null","messagePattern":"The path is null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.bindings.cs","lineNumber":237,"sourceCode":"\n        // Helper function to find the prefab root of an object\n        [FreeFunction]\n        [Obsolete(\"Use GetOutermostPrefabInstanceRoot if source is a Prefab instance or source.transform.root.gameObject if source is a Prefab Asset object.\")]\n        extern public static GameObject FindPrefabRoot([NotNull] GameObject source);\n\n        internal static GameObject CreateVariant(GameObject assetRoot, string path)\n        {\n            if (assetRoot == null)\n                throw new ArgumentNullException(\"The inputObject is null\");\n\n            if (!IsPartOfPrefabAsset(assetRoot))\n                throw new ArgumentException(\"Given input object is not a prefab asset\");\n\n            if (assetRoot.transform.root.gameObject != assetRoot)\n                throw new ArgumentException(\"Object to create variant from has to be a Prefab root\");\n\n            if (path == null)\n                throw new ArgumentNullException(\"The path is null\");\n\n            var assetRootObjectPath = AssetDatabase.GetAssetPath(assetRoot);\n            if (Paths.AreEqual(path, assetRootObjectPath, true))\n                throw new ArgumentException(\"Creating a variant of an object into the source file of the input object is not allowed\");\n\n            if (!Paths.IsValidAssetPath(path, \".prefab\"))\n                throw new ArgumentException(\"Given path is not valid: '\" + path + \"'\");\n\n            return CreateVariant_Internal(assetRoot, path);\n        }\n\n        [NativeMethod(\"CreateVariant\", IsFreeFunction = true)]\n        extern private static GameObject CreateVariant_Internal([NotNull] GameObject original, string path);\n\n        [StaticAccessor(\"PrefabUtilityBindings\", StaticAccessorType.DoubleColon)]\n        [NativeMethod(ThrowsException = true)]\n        extern private static GameObject SavePrefab_Internal([NotNull] GameObject root, string path, bool connectToInstance, out bool success);\n","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.bindings.cs#L219-L255","documentation":"Thrown by PrefabUtility.CreateVariant when the destination `path` argument is null. CreateVariant saves a new Prefab Variant asset to disk, so a null path makes no sense and is rejected before any native call. It is an ArgumentNullException, so it represents a programmer error rather than a runtime/environment condition.","triggerScenarios":"Calling `PrefabUtility.CreateVariant(rootGameObject, null)` or passing a variable that was never assigned an asset path. Triggered after the three earlier guards pass (assetRoot non-null, is a prefab asset, and is a prefab root), so the only remaining unmet condition is `path == null`.","commonSituations":"Building the destination path dynamically from user input, a text field, or a serialized field that was left empty in the Inspector. Editor scripts that construct the path via string concatenation where one operand is null. Porting code from SaveAsPrefabAsset that omitted the path argument.","solutions":["Pass a non-null asset path string ending in '.prefab', e.g. \"Assets/Prefabs/MyVariant.prefab\".","Compute the path from a folder selection or AssetDatabase.GenerateUniqueAssetPath before calling CreateVariant.","If the path is user-supplied, validate it is non-null/whitespace before invoking the API.","Guard with `string.IsNullOrEmpty(path)` and either early-return or prompt the user for a valid location."],"exampleFix":"// before\nvar variant = PrefabUtility.CreateVariant(root, (string)null);\n\n// after\nstring path = \"Assets/Prefabs/MyVariant.prefab\";\nif (string.IsNullOrEmpty(path))\n    throw new InvalidOperationException(\"Variant path must be set.\");\nvar variant = PrefabUtility.CreateVariant(root, path);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path))\n    throw new ArgumentException(\"Variant path must be provided.\", nameof(path));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct the variant path with AssetDatabase.GenerateUniqueAssetPath to guarantee a non-null, valid Assets-relative path.","Treat a null/empty path as a hard precondition; fail early with your own message before calling CreateVariant.","Centralize prefab-asset path building in one helper so all callers pass a validated string."],"tags":["prefab","unity-editor","argument-null","create-variant"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}