Tool Functions Through Animation Player

Godot Version

4.7.2

Question

Is there any way to call a function in editor through a animation player?
I am using an Animation Player to control the spawning of nodes in game at certain timestamps but I’d like to preview where they’d spawn in the editor. I have an AnimationPlayer with a call_method track which adds a node as a child. I’m hoping that I can get it to call the function in editor as opposed to only in game.
Thank you for your help!

I don’t see why you couldn’t.. have you tried? Just add @tool on top of the Node that holds the spawn function and see what happens when you test run the AnimationPlayer?

If you want your test node to show up in the scene tree as well you need to give it an owner (the edited scene’s root), which allows you to delete it again after your test

Yes, I have tried. The animation player, the node that does the spawning, and the spawned in node are all tool scripts.
The animation player is calling a function in the root node which runs add_child()

But it’s not literally adding it… Observably at least?

But the method is actually invoked, this you confirmed?

Have you tried this:

if Engine.is_editor_hint():
  spawned_in_node.owner = get_tree().edited_scene_root

This is needed for your node to appear in the Scene Tree.

No, no method is called even when I just have a print unfortunately

Hm. I’d have to reproduce this, but I do know that is your func takes required arguments, the animationplayer won’t call it. But if it prints at runtime and not in editor something else must be going on..

Try a minimal reproduction project to see if printing will work there… I can’t get to a laptop to try this for myself rn.

Creative thought: give the AnimationPlayer a script with @tool on top.

The animation player does have a tool script because it’s being used to control playing a song at the timestamp of the animation. I’ll create a mrp when I get access to my computer

Hi!

I just tried and confirmed, then used good old startpage.com and found this open issue:
Functions in AnimationPlayer's Call Method Tracks not called in the editor · Issue #75479 · godotengine/godot · GitHub

A workaround is suggested in this comment:

(edit, the second one was for godot 4)