Animation not playing on dynamically loaded glb

Hey,
I can’t seem to make the animation play on a runtime imported glb model.
Here is the project:
https://playcanvas.com/project/871331/overview/gambit

I’m using the following code to load the model and play the animation:

    var self = this;
    utils.loadGlbContainerFromAsset(this.glbAsset, null, this.glbAsset.name, function (err, asset) {
        var renderRootEntity = asset.resource.instantiateRenderEntity();
        self.entity.addChild(renderRootEntity);
        self.entity.animation.assets = asset.resource.animations;
        if(self.entity.animation.assets.length > 1)
            self.entity.animation.play(self.glbAsset.name + " 0");
        else
            self.entity.animation.play(self.glbAsset.name);


    });

It plays correctly in the playcanvas gltf viewer.
Hope someone can help me identify the problem.

Hi @Adolar13,

If you are using the render component to play animation you need to use the newer anim component, instead of the legacy animation component.

2 Likes

You can find several code examples on how to get it running in the following examples site:

https://playcanvas.github.io/#/animation/events

Thanks that worked,
here the amended code for anyone finding this post:

    utils.loadGlbContainerFromAsset(this.glbAsset, null, this.glbAsset.name, function (err, asset) {
        var renderRootEntity = asset.resource.instantiateRenderEntity();
        self.entity.addChild(renderRootEntity);
        // add animation
        renderRootEntity.addComponent('anim', { activate: true });  
        renderRootEntity.anim.assignAnimation('clip', asset.resource.animations[0].resource);
        renderRootEntity.anim.baseLayer.transition("clip");
    });
2 Likes