# How to loop a sequence of animation clips?

I have two animations that play one after another like so:

``````const action1 = mixer.clipAction( gltf.animations[ 4 ] );
const action2 = mixer.clipAction( gltf.animations[ 5 ] );

action1
.play();
setTimeout(function() {
action2
.setLoop(THREE.LoopOnce)
.play()
}, action1._clip.duration * 1000 - 500)
``````

Is there a way to infinitely loop the sequence so after action2, it starts from action 1? I tried with for and while loops around everything, but had no success.

I not speak English. I not sure if I understood right. do you want to play action1, then action2, then action1, then action2, then action1 etc…
if that so, then:
“”" I haven’t tested this. but I think the logic is something like this (maybe you need do just a little tweaks) “”"

``````//from somewhere
action1.play();

mixer.addEventListener( 'loop', this.vars.mixloop = (e)=> {

if(e.action._loopCount>=5){ //number of action1 loops before action2 start

mixer.clipAction("action1")._loopCount=0;
nowplaying="action1";
animator("action2", 0);

}

} );

//---------

animator (name:string, repetitions:any)
{
clearTimeout(time);

mixer.clipAction(name)._loopCount=0;
mixer.clipAction(name).repetitions=repetitions;
mixer.clipAction(name).reset();
mixer.clipAction(name).enabled=true;
mixer.clipAction(name).weight=1;

nowplaying=name;

time = setTimeout(()=>{

if(nowplaying=="action1")
{
mixer.clipAction("action2").enabled=true;
nowplaying="action1";
animatior("action2", 0)
}
else
{
mixer.clipAction("action1").enabled=true;
nowplaying="action2";
animatior("action1", 0)
}
},mixer.clipAction(name)._clip.duration*1000-500);

}
``````