{"record":{"id":"35455dbc219345fa","repo":"Unity-Technologies/UnityCsReference","slug":"bindings-must-be-non-null","errorCode":null,"errorMessage":"bindings must be non-null","messagePattern":"bindings must be non-null","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Animation/AnimationUtility.bindings.cs","lineNumber":245,"sourceCode":"\n        extern private static Type Internal_PropertyModificationToEditorCurveBinding(PropertyModification modification, [NotNull] GameObject gameObject, out EditorCurveBinding binding);\n        extern internal static PropertyModification EditorCurveBindingToPropertyModification(EditorCurveBinding binding, [NotNull] GameObject gameObject);\n\n        extern public static EditorCurveBinding[] GetCurveBindings([NotNull] AnimationClip clip);\n        extern public static EditorCurveBinding[] GetObjectReferenceCurveBindings([NotNull] AnimationClip clip);\n\n        extern public static ObjectReferenceKeyframe[] GetObjectReferenceCurve([NotNull] AnimationClip clip, EditorCurveBinding binding);\n\n        public static void SetObjectReferenceCurve(AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes)\n        {\n            Internal_SetObjectReferenceCurve(clip, binding, keyframes, true);\n            Internal_InvokeOnCurveWasModified(clip, binding, keyframes != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);\n        }\n\n        public static void SetObjectReferenceCurves(AnimationClip clip, EditorCurveBinding[] bindings, ObjectReferenceKeyframe[][] keyframes)\n        {\n            if (bindings == null)\n                throw new ArgumentNullException(nameof(bindings), $\"{nameof(bindings)} must be non-null\");\n            if (keyframes == null)\n                throw new ArgumentNullException(nameof(keyframes), $\"{nameof(keyframes)} must be non-null\");\n            if (bindings.Length != keyframes.Length)\n                throw new InvalidOperationException($\"{nameof(bindings)} and {nameof(keyframes)} must be of equal length\");\n\n            int length = bindings.Length;\n            for (int i = 0; i < length; i++)\n            {\n                SetObjectReferenceCurveNoSync(clip, bindings[i], keyframes[i]);\n            }\n            SyncEditorCurves(clip);\n            Internal_InvokeOnCurveWasModified(clip, new EditorCurveBinding(), CurveModifiedType.ClipModified);\n        }\n\n        internal static void SetObjectReferenceCurveNoSync(AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes)\n        {\n            Internal_SetObjectReferenceCurve(clip, binding, keyframes, false);\n            Internal_InvokeOnCurveWasModified(clip, binding, keyframes != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Animation/AnimationUtility.bindings.cs#L227-L263","documentation":"Thrown by AnimationUtility.SetObjectReferenceCurves when the bindings array is null. The method zips bindings with keyframes element-wise; a null bindings array has no Length to compare against keyframes.Length and no elements to loop. The guard uses nameof for a precise paramName and runs before any native call.","triggerScenarios":"Calling SetObjectReferenceCurves(clip, null, keyframes). Building the EditorCurveBinding[] from a LINQ query that returned null (rare, but possible from a custom collector returning null instead of empty). Reusing a stale field that was never initialized.","commonSituations":"Animation clip importers/post-processors that assemble object reference curves programmatically. Timeline tooling that deserializes binding lists from JSON where bindings was absent. Editor extensions syncing curves across clips.","solutions":["Construct bindings with an explicit empty array fallback: bindings ?? Array.Empty<EditorCurveBinding>().","Ensure bindings and keyframes are built in the same method with the same count.","Validate both arrays (null + length) in a shared helper before all Set*Curves calls.","If bindings are optional, early-return instead of calling with null."],"exampleFix":"// before\nAnimationUtility.SetObjectReferenceCurves(clip, bindings, keyframes);\n\n// after\nbindings ??= Array.Empty<EditorCurveBinding>();\nkeyframes ??= Array.Empty<ObjectReferenceKeyframe[]>();\nif (bindings.Length == 0) return;\nAnimationUtility.SetObjectReferenceCurves(clip, bindings, keyframes);","handlingStrategy":"validation","validationCode":"if (bindings == null || bindings.Length == 0) return;","typeGuard":"static bool HasBindings(EditorCurveBinding[] b) => b != null && b.Length > 0;","tryCatchPattern":null,"preventionTips":["Normalize collector output to Array.Empty<EditorCurveBinding>() instead of null.","Build bindings and keyframes in the same pass to keep them paired.","Centralize pre-validation for all Set*Curves calls."],"tags":["animation","argument-null","editor","csharp"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}