# Play all animations in sequence

**URL:** https://forum.castle-engine.io/t/play-all-animations-in-sequence/315
**Category:** Uncategorized
**Created:** [March 29, 2021, 4:10pm UTC](https://forum.castle-engine.io/t/play-all-animations-in-sequence/315 "2021-03-29T16:10:45Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [April 11, 2021, 11:53pm UTC](https://forum.castle-engine.io/t/play-all-animations-in-sequence/315/8 "2021-04-11T23:53:20Z")

</div>

Sorry for the delay!

In the new system, there’s no “animation that contains all other animations” as it didn’t seem very useful.

However you can implement a feature “play all available animations in a sequence” still, like this:

1. Get all possible animation names by `Scene.AnimationsList`. It is just a `TStringList` with all animation names.

2. Use the `TPlayAnimationParameters.StopNotification` mechanism to play one animation, and when it ends play the next one, and when it ends play the next again etc.

See my post [Sprite control with the new system - #2 by michalis](https://forum.castle-engine.io/t/sprite-control-with-the-new-system/311/2) where I mention this.

See `examples/animations/play_animation/code/gamestatemain.pas` for an example usage of `PlayAnimation` with `TPlayAnimationParameters`.

In your case, it would look like this (warning: untested quick draft code):

```auto
type
  TSomeClass = class // place this in any class you have handy
  private
    AnimList: TStringList;
    NextAnim: Integer;
    procedure RunNextAnimation(const Scene: TCastleSceneCore; const Animation: TTimeSensorNode);
  public
    procedure RunAllAnimations(const Scene: TCastleSceneCore);
  end;
     
procedure TSomeClass.RunAllAnimations(const Scene: TCastleSceneCore);
begin
  AnimList := Scene.AnimationsList;
  NextAnim := 0;
  RunNextAnimation(Scene, nil); // our RunNextAnimation implementation ignores 2nd param, ok to pass nil
end;

procedure TSomeClass.RunNextAnimation(const Scene: TCastleSceneCore; const Animation: TTimeSensorNode);
var
  NextAnimationName: String;
  Params: TPlayAnimationParameters;
begin
  NextAnimationName := AnimList[NextAnim];
  NextAnim := (NextAnim + 1) mod AnimList.Count;

  // play NextAnimationName, such that RunNextAnimation will be called again when it ends
  Params := TPlayAnimationParameters.Create;
  try
    Params.Name := NextAnimationName;
    Params.StopNotification := @RunNextAnimation;
    Scene.PlayAnimation(Params);
  finally FreeAndNil(Params) end;
end;

```

You may want to add here some “cancel” condition to `TSomeClass.RunNextAnimation`, otherwise it will just go on forever, until TCastleScene instance is finished.

---

_[View the full topic](https://forum.castle-engine.io/t/play-all-animations-in-sequence/315)._
