Search Unity

Bug InvalidCastException: Specified cast is not valid.

Discussion in 'Animation' started by freedom667, Sep 27, 2022.

  1. freedom667

    freedom667

    Joined:
    Sep 6, 2015
    Posts:
    425
    I get this error When I put keyframe from sprite sheet. I don't know why

    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. UnityEditorInternal.AnimationRecording.AddKey (UnityEditorInternal.IAnimationRecordingState state, UnityEditor.EditorCurveBinding binding, System.Type type, System.Object previousValue, System.Object currentValue) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs:513)
    3. UnityEditorInternal.AnimationRecording.ProcessModifications (UnityEditorInternal.IAnimationRecordingState state, UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs:420)
    4. UnityEditorInternal.AnimationRecording.Process (UnityEditorInternal.IAnimationRecordingState state, UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs:455)
    5. UnityEditorInternal.AnimationWindowControl.ProcessAutoKey (UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs:787)
    6. UnityEditorInternal.AnimationWindowControl.PostprocessAnimationRecordingModifications (UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs:771)
    7. UnityEditor.Undo.InvokePostprocessModifications (UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Undo/Undo.bindings.cs:274)
    8.  
    does anyone know the solution for this?

    Unity 2022.1.14f1
     
  2. freedom667

    freedom667

    Joined:
    Sep 6, 2015
    Posts:
    425
    Won't anyone help? It's important
     
  3. Akarias

    Akarias

    Joined:
    Oct 28, 2021
    Posts:
    1
    Hello ! This bug is still here ! I'm using Unity 2022.1.16f1 for a project with my students. The school installed this version. If you try to add a keyframe (in a animation) changing the sprite of a sprite renderer, it will give this error.

    The solution i found is to manually add a keyframe of type sprite renderer type. Then, if you try to modify the sprite again, the keyframe will add correctly. There is no sense ..

    I hope it's fixed in the other versions !