[SOLVED] Spawning template in scene problem: TypeError: node._updateGraphDepth is not a function

curiously enough I’m having trouble spawning a template asset into my scene using Javascript.
I made the following function which identifies the template by tag, and supposedly make it appear in the scene. However, when calling the “.addChild()” function everything breaks. All I get are some Playcanvas errors, and I cannot for the life of me figure out what goes wrong, cuz all console logs up until that point looks just fine.

java-script.prototype.addBox = function(typeTag){
    let box = this.app.assets.findByTag(typeTag)[0];
    console.log('box',box, typeTag);
    console.log('box 2',box);
    this.entity.addChild(box); //Something seems to break here

The error messages I receive are:

TypeError: node._updateGraphDepth is not a function


TypeError: children[i].syncHierarchy is not a function

do you want to call ‘instantiateRenderEntity’ instead of ‘instantiate’ ?

might be?
I basically want the same effect as dragging and dropping it into the scene in the interface…

Are you able to post a project to repro please?

I made a fresh repo now that produce the same error:

Ah, I see the issue now. instantiate and instantiateRenderEntity return an entity that should be added to the hierarchy.

However, you are trying to add the asset to the hierarchy. Effectively, you are doing this:


Instead of

let box = this.app.assets.findByTag(typeTag)[0];
let entity = box.resource.instantiate();

haha, wow. thanks.
Can’t believe I didn’t try this X)