sprite.anims.getCurrentKey ( ) returning `undefined`?

is there any reason why this is returning 'undefined' even though the character clearly loads into my game?

GetAnimName = function ( __sprite ) {
    __currentAnimName = ( __sprite.anims.getCurrentKey ( ) );
    return __currentAnimName;
}

// The movable character
this.sprite = this.physics.add.sprite (
    275, 575, "hero", 0
);

console.log ( 'Current Animation Name' + ' :: ' + GetAnimName ( this.sprite ) );

and the animation already works?

Any help as always, is GREATLY appreciated!

Thanks alot! :slight_smile:

It is undefined if the sprite has never loaded or played an animation.

I know I’m late to the party here, but I just figured this one out for myself: If you’re using Phaser 3.5 or above, the function is sprite.anims.getName() not getCurrentKey().

1 Like