[SOLVED] Problem with instantiating

Hello everyone,

I’m attempting to instantiate a template using the following code:

Test.attributes.add('box', { type: 'asset', assetType: 'template' })

// Initialize code called once per entity
Test.prototype.initialize = function () {
    let clone = this.box.resources.instantiate();
    this.entity.addChild(clone);
    clone.setLocalPosition(0, 0, 0);
    clone.enabled = true;
};

However, I encounter an error as shown in this image


. Upon checking the console, it appears that the resource is an array. Changing the code to this.box.resources.instantiate() resolves the issue. Is there a fix for this?
project : PlayCanvas | HTML5 Game Engine

NOTE : same thing doesn’t provide any issue in this game - PlayCanvas 3D HTML5 Game Engine

There is a typo on line 5, it should be:

let clone = this.box.resource.instantiate();

Note that resource should not be plural.

2 Likes

Hey, thanks for catching that! My bad on the typo. Appreciate your keen eye!
By the way, is there a button to mark this as solved, or should I edit the title myself?

I think you can just edit the title.

1 Like