+1 vote

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 ?

asked May 19 in Engine by pixel-boy (16 points)

2 Answers

0 votes
Best answer

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:

tool
extends AnimationPlayer

func print_test():
    print("test")

func _ready():
    var timer = Timer.new()
    add_child(timer)

    timer.wait_time = 0.5
    timer.connect("timeout", self, "print_test")
    timer.start()
answered May 28 by njamster (8,990 points)
selected May 29 by pixel-boy

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.

0 votes

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

answered May 21 by astrale-sharp (47 points)

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 printtest 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

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 :)

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.

Hey again :)
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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.