{"record":{"id":"ae701e3f1fecec5b","repo":"Unity-Technologies/UnityCsReference","slug":"gameobject","errorCode":null,"errorMessage":"gameObject","messagePattern":"gameObject","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Animation/AnimationUtility.bindings.cs","lineNumber":126,"sourceCode":"\n        [RequiredByNativeCode]\n        private static void Internal_CallAnimationClipAwake(AnimationClip clip)\n        {\n            if (onCurveWasModified != null)\n                onCurveWasModified(clip, new EditorCurveBinding(), CurveModifiedType.ClipModified);\n        }\n\n        [Obsolete(\"GetAnimationClips(Animation) is deprecated. Use GetAnimationClips(GameObject) instead.\")]\n        public static AnimationClip[] GetAnimationClips(Animation component)\n        {\n            return GetAnimationClipsInAnimationPlayer(component.gameObject);\n        }\n\n        // Returns the array of AnimationClips that are referenced in the Animation component\n        public static AnimationClip[] GetAnimationClips(GameObject gameObject)\n        {\n            if (gameObject == null)\n                throw new ArgumentNullException(\"gameObject\");\n\n            AnimationClip[] clips = GetAnimationClipsInAnimationPlayer(gameObject);\n\n            IAnimationClipSource[] clipSources = gameObject.GetComponents<IAnimationClipSource>();\n            if (clipSources.Length > 0)\n            {\n                var allClips = new List<AnimationClip>(clips);\n                for (int i = 0; i < clipSources.Length; ++i)\n                {\n                    var extraClips = new List<AnimationClip>();\n                    clipSources[i].GetAnimationClips(extraClips);\n\n                    allClips.Capacity = allClips.Count + extraClips.Count;\n                    foreach (var clip in extraClips)\n                    {\n                        if (clip != null)\n                            allClips.Add(clip);\n                    }","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Animation/AnimationUtility.bindings.cs#L108-L144","documentation":"Thrown by AnimationUtility.GetAnimationClips(GameObject) when gameObject is null. The method immediately calls GetAnimationClipsInAnimationPlayer(gameObject) and GetComponents<IAnimationClipSource>, both of which would dereference null; the guard fails fast with ArgumentNullException instead of an opaque NullReferenceException from native code.","triggerScenarios":"Calling GetAnimationClips(gameObject) where gameObject was destroyed between capture and use. Passing transform.gameObject from a destroyed Transform. A DestroyImmediate in the same frame leaves a 'not-null but destroyed' UnityEngine.Object that fails the == null override.","commonSituations":"Editor scripts scanning hierarchy during scene close. Prefab processing where the GameObject was unloaded. Timeline/Animator tooling iterating a filtered list that retained destroyed references.","solutions":["Null-check with UnityEngine.Object's overloaded == before calling: if (go == null) return;.","Cache validated references and re-check after any yield/EditorApplication.delayCall.","Use TryGetComponent or GetComponentsInChildren without destroyed objects by refreshing the query.","Guard against the destroyed-but-not-C#-null case explicitly: if (!go) return;."],"exampleFix":"// before\nvar clips = AnimationUtility.GetAnimationClips(target);\n\n// after\nif (target == null) { Debug.LogWarning(\"GameObject is null/destroyed; skipping.\"); return Array.Empty<AnimationClip>(); }\nvar clips = AnimationUtility.GetAnimationClips(target);","handlingStrategy":"type-guard","validationCode":"if (gameObject == null || !gameObject) { Debug.LogWarning(\"GameObject null or destroyed.\"); return Array.Empty<AnimationClip>(); }","typeGuard":"static bool IsLive(UnityEngine.Object o) => o != null;","tryCatchPattern":null,"preventionTips":["Use UnityEngine.Object's overloaded == to catch destroyed-but-not-C#-null objects.","Re-query hierarchy references after any DestroyImmediate or scene close.","Cache validated references and re-check after deferred callbacks."],"tags":["animation","argument-null","editor","lifecycle","csharp"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}