Skip to content

Instantly share code, notes, and snippets.

@Mikeysax
Last active October 22, 2023 23:44
Show Gist options
  • Save Mikeysax/5eed3ddc946ebddf81c5be6b5f62838c to your computer and use it in GitHub Desktop.
Save Mikeysax/5eed3ddc946ebddf81c5be6b5f62838c to your computer and use it in GitHub Desktop.
Automates the setting of interpolation mode on AnimationPlayer tracks in Godot 4.2+
extends AnimationPlayer
# HOW TO USE:
# Add this to an AnimationPlayer
# Make sure to set the interp mode on the node in the editor.
#
# Make sure to also set the FPS on the animation import as well.
# If you want to animate on 2s then set the fps to 12 or 15 and
# set Interp Mode to NEAREST
const NEAREST: int = 0
const LINEAR: int = 1
const CUBIC: int = 2
# Pick an interpolation mode for all tracks
@export_enum('NEAREST', 'LINEAR', 'CUBIC') var interp_mode: int = NEAREST
func _ready() -> void:
await owner.ready
change_interpolation_mode()
func change_interpolation_mode() -> void:
print("Interpolation Mode: ", interp_mode)
# Finds every animation on the selected AnimationPlayer
var anim_list = get_animation_list()
print("Animations Found: " + str(anim_list))
# Loops between every animation and apply the new interpolation mode
for anim_name: String in anim_list:
# Get the Animation by name
var anim_track: Animation = get_animation(anim_name)
# Get number of tracks (bones in your case)
var count: int = anim_track.get_track_count()
print("Modified Interpolation Mode " + anim_name)
# Change interpolation mode for every track
for index: int in count:
anim_track.track_set_interpolation_type(index, interp_mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment