• RuntimesGodot
  • Is there a way to check current animation in Godot?

Hi I wanted to check my previous animation before setting a new one via code, something like this:

var new_animation = ""
var new_scale_x = 0.237
if Sprite.get_animation_state() != new_animation:
Sprite.get_animation_state().set_animation(new_animation, true, 0)

This is so my animation doesn't get called multiple times during _physics_process and only gets called if the animation is not playing already.

At the moment it is giving me error as I am comparing an object to a string.

I would really appreciate any help.

Related Discussions
...

To check the current animation in Godot using the spine-godot runtime, you can use the get_current method on the SpineAnimationState to retrieve the current TrackEntry for a specific track. You can then compare the animation name of the current TrackEntry with the new animation you want to set. Here's an example of how you might implement this:

extends SpineSprite

func _physics_process(delta):
    var new_animation = "walk"
    var animation_state = get_animation_state()
    var current_entry = animation_state.get_current(0)  # Get the current TrackEntry for track 0

    if current_entry == null or current_entry.animation.name != new_animation:
        animation_state.set_animation(new_animation, true, 0)

This code checks if there is a current animation playing on track 0 and compares its name with the new animation. If they are different or if no animation is currently playing, it sets the new animation.

    Spinebot I'm still getting a similar issue, I've attached a larger snippet of the code for more context.

    The error I'm given is:
    Invalid access to property or key 'animation' on a base object of type 'SpineTrackEntry'.

    and it is referring to this line:
    if current_entry == null or current_entry.animation.name != new_animation: