Problem with assets.find?


I was trying to use assets.find to populate an entity on the fly but it keeps returning null.
I tried the model name, the filename and the ID but same result.
I made a test project here:

Hi @iXperiential,

The biggest thing goign on with your script was that when searching for an asset by name you need to include the full name as it appears in the editor. In this case the asset in the editor’s name includes the file extension.

You will find that doing this:

TestFind.prototype.initialize = function() {
    this.jenny ="SM_Jenny.glb", "model");
    if(this.jenny !== null)
        console.log("Success !");

should work for you.


It needs to be the full filename. You example didn’t include the .glb:

With the ID, it worked for me. Please note that it needs to be used with get function:

1 Like

Weird. I could have sworn I tried the full filename. Thanks!

Since we’re here, I tried to add some code to add a model on the fly.
I see the model in the hierarchy when I debug but it doesn’t show up. Is there anything I’m missing?
I modified the same project:

this.jenny ="SM_Jenny.glb", "model");
var self = this;
if(this.jenny !=null)
    var head = new pc.Entity(); = "MyHead";
    head.addComponent("model", {
        type: 'asset',
        asset: self.jenny

Your forgetting to add it as a child to the root.
insert this into the if statement self.addChild(head)


Thanks! I know I was missing something silly.

1 Like