Trouble controlling animationGroup imported from gltf

When I load my .gltf file and import animations, the model automatically starts playing one of the animationGroups (“Walk”), and I can’t get it to stop!

What I’ve tried is to get a reference to the animationGroup (in various ways), then call .stop(). I can only get it to stop by calling scene.stopAllAnimations().

this.canvas = <HTMLCanvasElement> document.getElementById("renderCanvas"); // Get the canvas element
this.engine = new BABYLON.Engine(this.canvas, true); // Generate the BABYLON 3D engine
this.scene = new BABYLON.Scene(this.engine);
this.camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 2, new BABYLON.Vector3(0,0,5), this.scene);
this.camera.attachControl(this.canvas, true);
this.light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), this.scene);
this.light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), this.scene);

BABYLON.SceneLoader.Append("./", "BaseCharacter.gltf", this.scene, (scene) => {
  BABYLON.SceneLoader.ImportAnimations("./", "BaseCharacter.gltf", this.scene, undefined, undefined, undefined, ()=>{
    /* this works
    this.scene.stopAllAnimations();
    */

    // this doesn't work
    let walk = this.scene.getAnimationGroupByName("Walk");
    walk.stop();

    /* this also doesn't work
    let g = this.scene.animationGroups;
    g[6].stop(); // used console.log to discover which animationGroup was playing 
    */
  });
});

this.engine.runRenderLoop(() => {
  this.scene.render();
});

I’m probably just not understanding how these controls are supposed to be used, so any insight would be much apprecaited ^_^.

Adding @thomlucc who just had fun with them :slight_smile:

Welcome to the forum @jlapointe!

Looking at your code above it may be the way you load the asset. To be able to repro, here is an example of playground where I stopped the default animation in the animationGroup:

  • If you comment line 27, you’ll see the default animation
  • if you uncomment this line 27, the animation is stopped
3 Likes

Thank you, that does the trick!

1 Like