Custom Import Process Extension For All Assets (Stepped Animation Interpolation)

Godot Version

Godot_v4.4.1-stable_mono_win64

Hi folks, :waving_hand:
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)


  1. Links are to engine 4.4 documentation. ↩︎

  2. Though there are others. ↩︎

  3. When the script is attached to the file they came in. ↩︎

Haven’t tested it but I think you could use EditorScenePostImportPlugin.post_process() for that.

I had tried hooking into _pre and _post process, my print statements weren’t writing anything in the console. I think my trouble is that I’m missing what to you need to do to register what asset files/types EditorScenePostImportPlugins are applied to.

Ah, I see. EditorScenePostImportPlugin is a plugin class so you’ll need to create a plugin.

You can register it with EditorPlugin.add_scene_post_import_plugin() and un-register it with EditorPlugin.remove_scene_post_import_plugin()

1 Like

:person_facepalming: I apparently cannot read. Thank you <3. I’ll report back later with how this goes.

Yeah, simply making sure the script is loaded correctly by a plugin is what I was missing. Thanks again :slightly_smiling_face:

If anyone comes to this thread just looking for a solution to importing stepped animations into their project, I will maintain an editor plugin for it at github.com/NateSavage/godot-stepped-animation-import.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.