Play and Paus Animation

Hi @Cedric Here in the playground a modal and animation is imported as a separate file using the method BABYLON.SceneLoader.LoadAssetContainer() . Is it possible to play or pause the animation by using let anim= scene.getAnimationGroupByName() and anim.stop() and anim.start() method ? . I have tried this but it is not working . Is there any possible way to do the same ? . This is the play ground link ---- https://playground.babylonjs.com/#IKXPN3#33

Hi @Anandu_Omanakuttan
Di you try to stop the animation like this :

Maybe I’m missing smth but just stopping animation should work.

Thanks for the replay @Cedric , But it will not work in my case , actually here in your replay the total animationis stop by the code "scene.stopAnimation(box); " but i need it indivudually.by picking animation name like "anim= scene.getAnimationGroupByName() " , can you please examin my situation with https://playground.babylonjs.com/#IKXPN3#33

I’m not familiar with animation. Maybe @PatrickRyan ?

@Anandu_Omanakuttan, the easiest way to keep track of your animation groups is to grab them when you load them into the scene. Basically, I changed the way you load the animation file slightly to do it asynchronously so we could add an await to make sure it was loaded before doing anything else.

// Mixamo animation
        animGroups.hiphopScene = await BABYLON.SceneLoader.ImportAnimationsAsync(baseUrl, "SillyDance.glb", scene, false, BABYLON.SceneLoaderAnimationGroupLoadingMode.Clean, null);
        animGroups.hiphopGroup = animGroups.hiphopScene.animationGroups[0];
        scene.stopAllAnimations();
        animGroups.hiphopGroup.play();
        animGroups.hiphopGroup.loopAnimation = true;

I added a stop all animation at the scene level to make sure that everything was stopped and we can control exactly what is playing. Animation groups will automatically play when loaded, so this is one way to make sure everything is reset. I grab the first animation group in the loaded animation file which should be the animation you wanted since there is only one in the file. Once you have that, you can play, pause, stop, or reset as much as needed.

I hope this helps, but let me know if you have more questions.

3 Likes