Godot Version
Godot_v4.4.1-stable_mono_win64
Hi folks,
I’m working on a project with stylized animation, all/most animations will be stepped only. So to reduce friction. I would like to add a step to the import process for all animations that sets the interpolation on each track to nearest.
I’ve found my way to EditorScenePostImport and EditorScenePostImportPlugin [1] as the right classes to extend the existing import pipeline for a file type without needing to replace it fully. The main difference between the two classes[2] seems to be that the non-plugin version needs to have it’s script attached on an object by object basis in order to function, while EditorScenePostImportPlugin
is applied project wide. I want this to be automatic, so clearly the the plugin version is the one I should use; However, I’ve had trouble getting it to work at all.
I’ve written a quick gd script using EditorScenePostImport
to ensure imported animations are stepped[3]. Would anyone with a bit more experience in this area mind showing an example for how to get an EditorScenePostImportPlugin
processing assets?
@tool
extends EditorScenePostImport
# Called by the editor when a scene has this script set as the import script in the import tab.
func _post_import(scene: Node) -> Object:
print("post import processing for scene %s" % scene.name)
iterate(scene)
return scene
func iterate(node: Node):
if node is AnimationPlayer == false:
for child in node.get_children():
iterate(child);
return
var animation_player = node as AnimationPlayer
print("converting animations to stepped...")
for anim_name in animation_player.get_animation_list():
print("- %s" % anim_name)
var animation = animation_player.get_animation(anim_name)
set_interpolation_type(animation, Animation.InterpolationType.INTERPOLATION_NEAREST)
func set_interpolation_type(animation: Animation, interpolation: Animation.InterpolationType) -> void:
var track_count = animation.get_track_count()
for track_id in track_count:
animation.track_set_interpolation_type(track_id, interpolation)