Unity-Technologies/UnityCsReference · error · ArgumentException
Allowed errors for keyframe reduction cannot be negative.
Error message
Allowed errors for keyframe reduction cannot be negative.
What it means
Thrown by the 3-arg GameObjectRecorder.SaveToClip when filterOptions.keyframeReduction is true and any of positionError, rotationError, scaleError, or floatError is negative. Keyframe reduction tolerances are magnitudes; negative values are meaningless and would break the reduction algorithm, so the guard throws ArgumentException before SaveToClipInternal.
Source
Thrown at Editor/Mono/Animation/GameObjectRecorder.bindings.cs:117
throw new ArgumentException("FPS can't be 0.0 or less");
if (!isRecording)
throw new InvalidOperationException("Cannot save to clip as there is nothing to save. The method TakeSnapshot() has not been called.");
SaveToClipInternal(clip, fps, k_DefaultCurveFilterOptions);
AnimationUtility.onCurveWasModified?.Invoke(clip, new EditorCurveBinding(), AnimationUtility.CurveModifiedType.ClipModified);
}
public void SaveToClip(AnimationClip clip, float fps, CurveFilterOptions filterOptions)
{
if (fps <= Mathf.Epsilon)
throw new ArgumentException("FPS can't be 0.0 or less");
if (filterOptions.keyframeReduction)
{
if (filterOptions.positionError < 0 || filterOptions.rotationError < 0 || filterOptions.scaleError < 0 || filterOptions.floatError < 0)
throw new ArgumentException("Allowed errors for keyframe reduction cannot be negative.");
}
if (!isRecording)
throw new InvalidOperationException("Cannot save to clip as there is nothing to save. The method TakeSnapshot() has not been called.");
SaveToClipInternal(clip, fps, filterOptions);
AnimationUtility.onCurveWasModified?.Invoke(clip, new EditorCurveBinding(), AnimationUtility.CurveModifiedType.ClipModified);
}
[NativeMethod("SaveToClip")]
extern void SaveToClipInternal(AnimationClip clip, float fps, CurveFilterOptions filterOptions);
extern public void ResetRecording();
// Obsolete
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[Obsolete("The GameObjectRecorder constructor now takes a root GameObject", true)]View on GitHub (pinned to 225b0fbdb5)
Solutions
- Default all error fields to 0 (or a small positive epsilon) instead of negative sentinels.
- Clamp each field: Mathf.Max(0f, value) before passing.
- Validate the whole CurveFilterOptions in a helper when keyframeReduction is on.
- If reduction is unwanted, set keyframeReduction = false rather than negative errors.
Example fix
// before filterOptions.positionError = -1; recorder.SaveToClip(clip, fps, filterOptions); // after filterOptions.positionError = Mathf.Max(0f, filterOptions.positionError); filterOptions.rotationError = Mathf.Max(0f, filterOptions.rotationError); filterOptions.scaleError = Mathf.Max(0f, filterOptions.scaleError); filterOptions.floatError = Mathf.Max(0f, filterOptions.floatError); recorder.SaveToClip(clip, fps, filterOptions);
Defensive patterns
Strategy: validation
Validate before calling
if (filterOptions.keyframeReduction) { filterOptions.positionError = Mathf.Max(0f, filterOptions.positionError); filterOptions.rotationError = Mathf.Max(0f, filterOptions.rotationError); filterOptions.scaleError = Mathf.Max(0f, filterOptions.scaleError); filterOptions.floatError = Mathf.Max(0f, filterOptions.floatError); } Prevention
- Never use negative sentinels for 'unset'; use 0 or disable keyframeReduction.
- Clamp all error fields to >= 0 before calling.
- Validate the whole CurveFilterOptions in a helper.
When it happens
Trigger: Setting CurveFilterOptions errors to -1 to mean 'unset'. Loading filter options from config where fields defaulted to -1. Copying values from a UI that allowed negatives.
Common situations: Serialized CurveFilterOptions with sentinel -1 for 'no value'. Editor UI sliders with no lower bound clamp. Tooling that reuses a single options struct and partially resets it.
Related errors
- FPS can't be 0.0 or less
- Binding type should derive from Unity type.
- Cannot save to clip as there is nothing to save. The method
- gameObject
- bindings must be non-null
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/e1d3622f61637f79.
Report an issue: GitHub.