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); = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 2, new BABYLON.Vector3(0,0,5), this.scene);, 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 doesn't work
    let walk = this.scene.getAnimationGroupByName("Walk");

    /* 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(() => {

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

Thank you, that does the trick!

1 Like