Addcomponent model asset

Hi, I cant figure it out from the documentation how to create an asset dynamically. For a box:

entity.addComponent("model", {
            type: 'box',
        });

this worked fine for a box but I would like to dynamically create an entity with a custom model imported as an asset like this:

entity.addComponent("model", {
            type: 'asset',
            asset: 'hexagon.json'
        });

What am I doing wrong?

1 Like

The asset field in a component, takes either an asset object or the asset id, not a path.

You can do this:

var modelAsset = app.assets.find("My Model", "model");
entity.addComponent("model", {
    type: "asset",
    asset: modelAsset
});
3 Likes