{"record":{"id":"18c3c15ce69713a2","repo":"Unity-Technologies/UnityCsReference","slug":"the-prefab-you-want-to-instantiate-is-null","errorCode":null,"errorMessage":"The Prefab you want to instantiate is null.","messagePattern":"The Prefab you want to instantiate is null\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorUtility.cs","lineNumber":680,"sourceCode":"                go.TryGetComponent<Renderer>(out var renderer))\n            {\n                // Case 1297670: Force the ambient probe for object preview in SRP.\n                renderer.lightProbeUsage = LightProbeUsage.Off;\n            }\n        }\n\n        internal static void InitInstantiatedPreviewRecursive(GameObject go)\n        {\n            go.hideFlags = HideFlags.HideAndDontSave;\n            ConfigurePreviewObjectSRP(go);\n            foreach (Transform c in go.transform)\n                InitInstantiatedPreviewRecursive(c.gameObject);\n        }\n\n        internal static GameObject InstantiateForAnimatorPreview(Object original)\n        {\n            if (original == null)\n                throw new ArgumentException(\"The Prefab you want to instantiate is null.\");\n\n            GameObject go = InstantiateRemoveAllNonAnimationComponents(original, Vector3.zero, Quaternion.identity) as GameObject;\n            go.name = go.name + \"AnimatorPreview\";       //To avoid FindGameObject picking up our dummy object\n            go.tag = \"Untagged\";\n            InitInstantiatedPreviewRecursive(go);\n\n            Animator[] animators = go.GetComponentsInChildren<Animator>();\n            for (int i = 0; i < animators.Length; i++)\n            {\n                Animator animator = animators[i];\n\n                animator.enabled = false;\n                animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;\n                animator.logWarnings = false;\n                animator.fireEvents = false;\n            }\n\n            // We absolutely need an animator on the gameObject","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorUtility.cs#L662-L698","documentation":"InstantiateForAnimatorPreview requires a non-null prefab/prefab-asset; passing null throws ArgumentException immediately because the subsequent InstantiateRemoveAllNonAnimationComponents call and component enumeration would NRE. This is the standard guard used when Unity needs to build a stripped-down Animator preview object from a prefab.","triggerScenarios":"Calling InstantiateForAnimatorPreview(null), or passing an object reference whose Unity asset was destroyed/unloaded between assignment and call. Editor code that previews an Animator from a selection whose prefab was deleted from disk.","commonSituations":"A custom inspector or preview window that grabs a target via EditorGUILayout.ObjectField and the user clears the field (yielding null) before the preview redraws. Loading a scene whose referenced prefab is missing (red meta/missing reference) and the preview hook fires.","solutions":["Null-check the argument before calling InstantiateForAnimatorPreview and skip the preview when it is null.","If the source is an ObjectField, also test the resolved object with 'if (target == null)' rather than 'is null', since destroyed UnityEngine.Object instances are != null only via the overloaded operator.","Re-resolve the prefab by GUID/asset path if it may have been reimported."],"exampleFix":"// before\nvar preview = EditorUtility.InstantiateForAnimatorPreview(target);\n// after\nif (target != null)\n    var preview = EditorUtility.InstantiateForAnimatorPreview(target);\nelse\n    return null;","handlingStrategy":"validation","validationCode":"if (original == null) // UnityEngine.Object overload: true for destroyed/missing\n    return null;\nGameObject preview = EditorUtility.InstantiateForAnimatorPreview(original);","typeGuard":"static bool IsUsablePrefab(UnityEngine.Object o) => o != null && o is GameObject;","tryCatchPattern":null,"preventionTips":["Use '!= null' (not 'is null') for UnityEngine.Object to catch destroyed instances.","In preview windows, revalidate the target on every repaint, not just on enable.","Resolve prefabs by GUID/asset path so a missing reference is detected before preview."],"tags":["null-argument","prefab","animator","preview","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}