logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class AnimationClipCurveCache

    Holds one stable UnityEngine.AnimationCurve instance per UnityEditor.EditorCurveBinding for the lifetime of a clip selection, plus a shadow copy of each for undo-correct commits.

    Inheritance
    object
    AnimationClipCurveCache
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    Namespace: Serenity.Editor.AnimationHub.Gui
    Assembly: Serenity.AnimationHub.Editor.dll
    Syntax
    public sealed class AnimationClipCurveCache
    Remarks

    CONSTRAINT: UnityEditor.AnimationUtility.GetEditorCurve(UnityEngine.AnimationClip,UnityEditor.EditorCurveBinding) returns a fresh instance on every call, but UnityEditor.EditorGUILayout.CurveField(UnityEngine.AnimationCurve,UnityEngine.GUILayoutOption[])'s popup (the Curve Editor window) mutates the exact instance it was handed, in place, and keeps referencing it across repaints while open. Re-fetching per OnGUI would hand the popup a different instance every frame, orphaning a mid-edit gesture — GetLiveCurve(EditorCurveBinding) always returns the same cached instance back. A second consequence follows: because the popup mutates in place, by the time a change-check fires the "before" value is already overwritten — the field and the edited result are the same object. CommitEditedCurve(EditorCurveBinding) uses each binding's shadow copy to stay undo-correct anyway.

    Constructors

    AnimationClipCurveCache()

    Declaration
    public AnimationClipCurveCache()

    Methods

    CommitEditedCurve(EditorCurveBinding)

    Commits the in-place mutation a CurveField already applied to GetLiveCurve(EditorCurveBinding)'s returned instance, in the exact order undo-correctness requires:

    1. write the binding's SHADOW (the last known-good, pre-edit value) directly onto the clip via UnityEditor.AnimationUtility.SetEditorCurve(UnityEngine.AnimationClip,UnityEditor.EditorCurveBinding,UnityEngine.AnimationCurve), no undo scope — this guarantees the clip's on-disk curve equals the shadow immediately before step 2, regardless of drift, since the live curve's own pre-edit value was already overwritten in place;
    2. open one AnimationClipEditScope (via WriteCurve(WriteCurveInput)) and write the mutated live curve — the single undo entry for the whole gesture;
    3. refresh the shadow to a fresh clone of the now-committed live curve. No-op when binding was never fetched via GetLiveCurve(EditorCurveBinding).
    Declaration
    public void CommitEditedCurve(EditorCurveBinding binding)
    Parameters
    Type Name Description
    EditorCurveBinding binding

    Disable()

    Declaration
    public void Disable()

    Enable(Action)

    Subscribes to the two events that can make the cache stale without any call of ours: an undo/redo reverting the clip behind our back, and another editor (Unity's own Animation window) writing to the same clip concurrently. Pair with Disable().

    Declaration
    public void Enable(Action repaint)
    Parameters
    Type Name Description
    Action repaint

    GetLiveCurve(EditorCurveBinding)

    The stable, cache-owned curve instance for binding — fetched once and reused on every later call, so a CurveField popup targeting it is never orphaned. Null when there is no clip, or no curve at binding.

    Declaration
    public AnimationCurve GetLiveCurve(EditorCurveBinding binding)
    Parameters
    Type Name Description
    EditorCurveBinding binding
    Returns
    Type Description
    AnimationCurve

    InvalidateAll()

    Clears every cached instance. Called after an undo/redo, an external curve edit, or any direct engine call (key add/remove, binding add/remove) that changed curves without this cache.

    Declaration
    public void InvalidateAll()

    SetClip(AnimationClip)

    Switches to a new clip, clearing every cached instance. No-op when reference-equal to the clip already set.

    Declaration
    public void SetClip(AnimationClip clip)
    Parameters
    Type Name Description
    AnimationClip clip

    Events

    CurvesInvalidated

    Raised at the end of every InvalidateAll() — including the ones triggered by an undo/redo or an external curve edit this cache did not initiate itself. The preview scrubber subscribes so a stale sampled pose resyncs to whatever the clip's curves actually are now, not just to edits made through this panel's own curve field.

    Declaration
    public event Action CurvesInvalidated
    Event Type
    Type Description
    Action
    In this article
    © 2026 Serenity. All Rights Reserved