GLB one shot animations

Hello all,

i have a glb loader that is shown below. Then on another script i have

    this.wheels.anim.baseLayer.transition('WheelsMove', 0.1); 

when i run it as is and click the button nothing happens. But if I change the loop flag to true in the glb import and i click the button the animation starts over from the beginning and plays through. this is what i would expect to happen, but the animation then keeps looping. Why does this not work with the flag set to false?

LoadGlb.prototype.initialize = function() {
    var self = this;
    utils.loadGlbContainerFromAsset(this.glbAsset, null, this.glbAsset.name, function (err, asset) {
        var renderRootEntity = asset.resource.instantiateRenderEntity();
        self.entity.addChild(renderRootEntity);
  
        if(this.animationName === "Wheels"){
            var animationAsset = asset.resource.animations[0];
            this.entity.anim.assignAnimation("WheelsMove", animationAsset.resource,1, false);

        }

   }.bind(this));

};

I think your animation keeps looping because you haven’t stated otherwise.

Currently, your “false” value in your script is set to the “speed” parameter, not “loop” parameter.

https://developer.playcanvas.com/en/api/pc.AnimComponent.html#assignAnimation

So your script line should be:

this.entity.anim.assignAnimation("WheelsMove", animationAsset.resource, "LAYER_NAME", 1, false);

Note that I implemented LAYER_NAME because it seems that you haven’t included it and that is why your looping isn’t working.

1 Like

oh wow having the layer name seemed to work
i was going off of the code editor hints

1 Like

Looks like the code editor picked up the wrong function to show (most likely because it’s in a callback)

It showed you the assignAnimation for the layer object https://developer.playcanvas.com/api/pc.AnimComponentLayer.html#assignAnimation instead of the animComponent one

1 Like

would have thought it would have thrown and error if it didnt have all the info it needed or some of the variable types were in the wrong spot.

Not with Javascript. Chances are that JS would convert false into a string when used in that context. See What the... JavaScript? - YouTube