MZ How can remove existing animation?

If I play a new animation before the end of the animation, it will overlap with the existing animation. (I am playing animation on the map) I hope the existing animation will be deleted when I play the new animation. Is there a way?
You could try one of these in a Script command:
  • Clear All Animations:
    JavaScript:
    SceneManager._scene._spriteset?.removeAllAnimations();

  • Clear Character Animation:
    JavaScript:
    // MZ, stop all ongoing animations on the player
    const spriteset = SceneManager._scene._spriteset;
    if (spriteset) {
      spriteset._animationSprites.filter(
        s => s.targetObjects.includes($gamePlayer)
      ).forEach(
        s => spriteset.removeAnimation(s)
      );
    }
    This is for the player. You can replace $gamePlayer with $gameMap.event(123) to target map event 123 instead.
(These MZ examples are from the "Character Effects" section of the MV / MZ Script Call List.)
Isn't there a box you can check with "Wait" on it when you select the show animation command? That'd make the first animation finish before starting a new one.

(edit: this one)

1692000069505.png
@Navas but the OP doesn't want to finish the animation, he wants to cancel it.

most likely because the original plays in a loop
Thank you everyone!

You could try one of these in a Script command:
  • Clear All Animations:
    JavaScript:
    SceneManager._scene._spriteset?.removeAllAnimations();

  • Clear Character Animation:
    JavaScript:
    // MZ, stop all ongoing animations on the player
    const spriteset = SceneManager._scene._spriteset;
    if (spriteset) {
      spriteset._animationSprites.filter(
        s => s.targetObjects.includes($gamePlayer)
      ).forEach(
        s => spriteset.removeAnimation(s)
      );
    }
    This is for the player. You can replace $gamePlayer with $gameMap.event(123) to target map event 123 instead.
(These MZ examples are from the "Character Effects" section of the MV / MZ Script Call List.)
It works very well. Thank you.

Isn't there a box you can check with "Wait" on it when you select the show animation command? That'd make the first animation finish before starting a new one.

(edit: this one)

View attachment 273318
It wasn't what I wanted, but thank you for replying!
Great, happy RPG Making! 👋

Original thread: https://forums.rpgmakerweb.com/threads/how-can-remove-existing-animation.160293/