Addcomponent coding help

Hi Everyone, had a simple question I’ve been stuck on. how can we load a model legacy component with an GLB asset?

tried following this addcomponent to load my model instead of the box

entity.addComponent("render", {

        type: 'box'

    });

thanks in advance

Hi,

The legacy component which is “model” doesn’t work with glb assets, you have to use the Render component to load it.
Here is an example of loading glb assets and adding a render component at run time to render them
https://playcanvas.com/editor/scene/1019167

nice. thanks, it works well. also. can I use to add/load the animation legacy ?

Yes, it can work with the animation legacy component, but I would suggest you use the new Anim component, here is an example of loading animations from a glb and running them through the Anim component:
https://playcanvas.com/project/877109/overview/multiple-animations

1 Like

Slight correction: You can use the Model Component with GLB model assets (you have to untick ‘Import Hierarchy in Asset Settings’) and the Model Component works with both the Animation and Anim Component

    var modelAsset = this.app.assets.find('ambulance.glb', 'model');
    this.entity.addComponent('model', {
        asset: modelAsset,
        type: 'asset'
    });
1 Like

can I also add an animation with this model? using addcomponent?

Yes

var animationAsset = this.app.assets.find(‘walk.glb’, ‘animation’);
this.entity.addComponent(‘animation’, {
asset: animationAsset ,
type: ‘asset’
});