Is there a way to remove keys from animation player with code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ArAdev
:warning: Old Version Published before Godot 3 was released.

Hi, I searched in the documentation and I didn’t find a way to do it. The thing is that in my game, the arms of the player are moved manually, so I need to temporary remove it´s keys from the animation player to do it, because if the keys from the arm are present, the arms will stop it´s movement and only do what the animation has predefined.
I know I could make different animations with and without the arms, but that would mean making a lot of different animations to do the action and that would break the order of the game.
So is there a way to delete specific keys from an animation with code?

:bust_in_silhouette: Reply From: avencherus

Yes, you can find it here: Animation — Godot Engine (stable) documentation in English

You have to get the animation from the player, and then use the track functions as desired, giving the track index and the keyframe index. Should be the order that they appear, starting with 0.

var player = get_node("AnimationPlayer")
var anim = player.get_animation("my_anim_name")
anim.track_remove_key(track_idx, key_frame_idx)

Ok, I searched in the animation player section from the docs , and not from the animation section, this is very useful, thanks!

ArAdev | 2018-01-10 05:47

You’re welcome. :slight_smile:

avencherus | 2018-01-10 06:46