Call method with AnimationPlayer and tool mode

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pixel-boy

I would like to call a method ( print_test )
enter image description here
With an AnimationPlayer, directly in the editor using tool mode
enter image description here
But it doesn’t work, am I doing it wrong or is it not possible ?

:bust_in_silhouette: Reply From: astrale-sharp

Hey :slight_smile:
It is possible!
Please describe to me what you do to test it and what happens
I’ll be happy to help: )

Hi, thank you for your reply !
About what I do →
1- I created a scene with a Node2D
2 - I added a child AnimationPlayer node on this Node2D
3 - I assigned a script to the 2D node with the keyword “tool” at the start
4 - And created a function called print_test which prints the message “test”
5 - I created an animation and called the print_test method (like on image 2)

I launch the animation in the editor, but the function does not launch despite the tool mode however if I launch the game it works normally

pixel-boy | 2020-05-21 22:22

Hey again: )
I think you misunderstood the tool keyword so im going to explain that to you
First, if you remove the tool keyword im pretty sure your animation will work both in game and in the editor

The tool keyword is when you want a script to work in the editor: it might help you edit your levels or such, it might draw to the screen to make it more clear what your objects do: go watch that excellent video from gdquest on youtube (gdquest tool on youtube)
Dont hesitate if you need some more help :slight_smile:

astrale-sharp | 2020-05-23 09:12

I think you did not understand my request, I have already used the tool mode and I know how it works.

In my case, I use an animation of an AnimationPlayer to call a method, when I play the animation during the game, it works and the function is called, I get my print(“test”).

What I would like is to have the same thing when I preview the animation directly in the editor.
I thought that the tool mode would do that but it doesn’t seem to work, maybe Godot doesn’t manage this possibility.

pixel-boy | 2020-05-28 14:56

Hey again :slight_smile:
the basic behavior of the engine is to do what you want : printing “test” when you preview the animation in the editor,
I encourage you to try without the tool keyword and tell me if it works or not,
if it doesnt, I’ll try to do some more research to see if i can help

astrale-sharp | 2020-05-30 06:39

:bust_in_silhouette: Reply From: njamster

I can confirm that it doesn’t work. However, I cannot tell you if that’s a bug or just a limitation of the tool-keyword / AnimationPlayer. You may open an issue.

Meanwhile you can use something like this as a workaround:

extends AnimationPlayer

func print_test():

func _ready():
	var timer =

	timer.wait_time = 0.5
	timer.connect("timeout", self, "print_test")

I’ll try to open an issue, thank you for your answer ! I do not know if it is possible but this feature could be practical.

pixel-boy | 2020-05-29 17:54