How to create an entity with a mesh with script

Hi guys.

I’m trying to create a place object system on PlayCanvas where the player will have an inventory with a bunch of items and can place it on the floor, like The Sims. It’s working fine with a box, but I can’t work with an entity.

First, I created a store script that receives a json formats with some entities:

StoreController.attributes.add('data', {
    type: 'json',
    array: true,
        name: 'item',
        type: 'entity'
    }, {
        name: 'price',
        type: 'number',
        default: 10

And I linked some entities. These one are them for test:

And then when you click on it, you buy them.

Second, I created an inventory that takes these items and lists them and when you click on it, you can place it on the floor. But the problem is on bellow:

PlaceObject.prototype.startPlacing = function(item) {

    this.isPlacing = true;
    this.currentItem = new pc.Entity();

    this.currentItem.addComponent("render", {
        type: 'asset',
        asset: item.render.meshInstances[0]

When I test the code with the ‘BOX’ type the script works very well, but when I tried to render a mesh that I received in ‘item’, it doesn’t work anymore.

What I get in ‘item’ is an entity.

I’ve tried to use ‘item.render’, ‘item.render.meshInstances[0]’, ‘item.render.meshInstances’, ‘item.resouce’, ‘item.model’ but none of them worked, the mesh doesn’t render in the scene…

This is the project:
Overview | Dashboard | Habbo | PlayCanvas | 3D HTML5 & WebGL Game Engine

Could anyone help me?

I am not 100% sure this could work, but could you define the objects as script attributes, or use or tag and then clone that object? You could then set the cloned entity’s location to the player.

Here is a proof of concept: PlayCanvas 3D HTML5 Game Engine