Godot Version
v4.5.1
Issue
Hello devs, I’m currently trying to automate my animation import process. I want animations Saved to File and Keep Custom Tracks enabled by default, as locating each new animation to enable keep custom tracks every single time I want to add a new set of animation(s) kinda sucks. To do this, I have created a simple plugin that loads a script, following the solution to this post → Automatically set “keep_custom_tracks” on imported animations
The imported file has the plugin’s main script path given under Import Script; however, when I reimport the file, it throws the following error:
Script is not a subtype of EditorScenePostImport
Changing the loaded script extends to EditorScenePostImport breaks it, so I don’t know where to go. The main script is import.gd:
@tool
extends EditorPlugin
var process_plugin
func _enter_tree() -> void:
process_plugin = preload("res://addons/anim_importer/post_import.gd").new()
add_scene_post_import_plugin(process_plugin)
func _exit_tree() -> void:
remove_scene_post_import_plugin(process_plugin)
process_plugin = null
And the loaded script, post_import.gd is as follows:
@tool
extends EditorScenePostImportPlugin
func _get_import_options(path: String) -> void:
add_import_option_advanced(TYPE_BOOL,"animation/save_animations_to_file", false, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED)
add_import_option_advanced(TYPE_STRING, "animation/animations_dir", "", PROPERTY_HINT_DIR)
add_import_option("animation/keep_custom_tracks", false)
func _get_option_visibility(path: String, for_animation: bool, option: String) -> Variant:
var save_animations = get_option_value("animation/save_animations_to_file")
match option:
"animation/animations_dir":
return save_animations
"animation/keep_custom_tracks":
return save_animations
return true
func _pre_process(scene: Node) -> void:
var original_out = get_option_value("_subresources")
var subresources = {}
iterate(scene, subresources)
var animations = subresources.get("animations", [])
if not animations.is_empty():
var new_out = {}
new_out["animations"] = {}
for animation in animations:
new_out["animations"][animation] = {
"save_to_file/enabled": true,
"save_to_file/path": original_out["animations"][animation]["save_to_file/path"],
"save_to_file/keep_custom_tracks": true}
original_out = new_out
func iterate(node:Node, subresources:Dictionary) -> void:
if node == null: return
if node is AnimationPlayer:
if not subresources.has("animations"):
subresources["animations"] = []
var animations = subresources["animations"]
animations.append_array(node.get_animation_list())
for child in node.get_children():
iterate(child, subresources)
As mentioned, this is near identical to the solution in the linked topic.
What do I do next? Any help is appreciated.