Hi. I’m trying to show assets using runtime. but seems like I’m missing some important coding, would like to ask how can I use any asset using this script. thanks in advance
Hi @Genesis_Miranda,
Try changing this:
var entity = new pc.Entity();
var self = this;
self.entity.enabled = true;
// Add a Component to the Entity
var modelAsset = this.app.assets.get(64702342);
entity.addComponent("model", {
type: "asset",
asset: modelAsset
});
To this (using the asset name, instead of id, since that can break when forking the project):
var self = this;
var modelAsset = this.app.assets.find('Iron_Man_Mark_44_Hulkbuster_fbx.glb');
modelAsset.ready(function () {
self.entity.model.asset = modelAsset;
});
this.app.assets.load(modelAsset);
It works, thank you!
1 Like