# Detect MMD animation is end or not

**URL:** https://discourse.threejs.org/t/detect-mmd-animation-is-end-or-not/30331
**Category:** Questions
**Tags:** animation
**Created:** [September 28, 2021, 1:00pm UTC](https://discourse.threejs.org/t/detect-mmd-animation-is-end-or-not/30331 "2021-09-28T13:00:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Anne](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Anne](https://discourse.threejs.org/u/Anne)
#### Post date: [September 28, 2021, 1:00pm UTC](https://discourse.threejs.org/t/detect-mmd-animation-is-end-or-not/30331/1 "2021-09-28T13:00:15Z")

</div>

MMD animation will loop after ended. Is there any way to stop the loop?  
I don’t want the animation loop again. Just play one time.  
I can just pause/play when the animation is not ended, but I don’t know how to detect the whole animation is ended or not.  
Hope someone know the answer. A lot of thanks!

Here is the code.

```javascript
function animate() {

	requestAnimationFrame( animate );
	render();
	
}

function render() {

	if (status == "play"){
		helper.update( clock.getDelta() );							
	}

	effect.render( scene, camera );
}

```

---

<div class="post-metadata">

### Author: ![MixTeR](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mixter/32/26747_2.png) [@MixTeR](https://discourse.threejs.org/u/MixTeR)
#### Post date: [September 29, 2021, 11:36pm UTC](https://discourse.threejs.org/t/detect-mmd-animation-is-end-or-not/30331/2 "2021-09-29T23:36:04Z")

</div>

**MMD animation will loop after ended. Is there any way to stop the loop?**

to avoid loop you need to set the repetitions in your mixer

your\_mixer\_var=helper.objects.get(variable\_model);  
your\_mixer\_var.mixer.clipAction(animation\_name\_or\_path).repetitions=0;

**how to detect the whole animation is ended or not?**

you need a eventListener

your\_mixer\_var.addEventListener( ‘finished’, a\_variable = (e)=\>  
{  
//YOUR CODE HERE (will run when the animation has ended)

//\*\*remember delete the addeventlistiner to avoid multiple instances  
your\_mixer\_var.removeEventListener(‘finished’, a\_variable);  
});

**OTHER WAY**

You can use addEventlistener loop to detect when is looping and stop the animation

your\_mixer\_var.addEventListener( ‘loop’, your\_variable\_loop = (e)=\> {

//This code runs in every loop

```
your_mixer_var.clipAction(animation_name_or_path).stop();

```

//IF your want detroy the loop listener  
//\*\*remember delete the addeventlistiner to avoid multiple instances

your\_mixer\_var.removeEventListener(‘loop’,your\_variable\_loop);  
});

for more info look the documentation for AnimationAction

[https://threejs.org/docs/?q=animation#api/en/animation/AnimationAction](https://threejs.org/docs/?q=animation#api/en/animation/AnimationAction)

:3
