Topic was automatically imported from the old Question2Answer platform.
Asked By
ddarkmoto
HI everyone, I currently have these lines of code:
if hit == true:
state_machine.travel("death")
queue_free()
My objective is to finish the animation of a certain node before removing it from a parent node. My problem is, state_machine.travel(“death”), and queue_free() is being executed simultaneously. Is there a way to determine if the animationtree’s finished playing the animation? Thanks
You mean the AnimationPlayer, used by AnimationTree? Nope, it doesn’t return any signals when used in an AnimationTree. And AnimationTree doesn’t have signals for that.
Also is_playing() doesn’t work in AnimationTree, since it always returns TRUE.
So i think there are a lot of issues to be fixed in AnimationTree.
Kinda late but I found a solution, It’s a bit bothersome but it works
You can use a “Call Method Track” in every animation
Add a key at the end, select a method with a string parameter and write the animation name in the key “Args” section to pass it
Since I only needed it for a few animations it wasn’t that bad, but between this and other common issues like only having boolean conditionals or not being able to edit the animation speed directly without a blend node… it really screams the need for an update of the animation tree
Also, a simple solution for your problem would be to directly choose the queue_free() method in the call method track (search it at the top)
I’m kind of new in GODOT and I had this same issue and could find a direct method. But I found a way around the issue that is kind of easy to implement (at least for me).
For StateMachines in AnimationTree exists a function that could get the current time of the animation (get_current_play_position). When played, this value should be the same or increased its value. But when the animation ends, its value goes directly to 0.
My walk around needs a global variable saving the prior value of the play, and a function that compares the prior value to the current animation value.
I leave you my code. Hope this could be helpful
var prior_play_position:float = 0.0
func Get_Is_Playing():
var temp:AnimationNodeStateMachinePlayback = animation_tree.get("parameters/playback")
var current_play_position:float = temp.get_current_play_position()
if prior_play_position > current_play_position:
prior_play_position = current_play_position
return false
else:
prior_play_position = current_play_position
return true
Please keep in mind that I use this for knowing when to change this animation. When an animation is changed, the I initialize the prior value to 0.