[SOLVED] Applying componets to clones?

Hello there, I wanna create a building system for my game
whenever you click it should create a wall but then again there’s not a collision component in the clone even when I add it to the original it doesn’t do anything, is there a way to fix this?

Here’s my script:

var BuildSystem = pc.createScript('buildSystem');

var items = [36841159];


BuildSystem.attributes.add('wallAsset',{type:'asset',title:'WallAsset'});


// initialize code called once per entity
BuildSystem.prototype.initialize = function() {
    this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMove, this);  
    this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onClick, this);
    this.InBuildMode = false;
    this.CurrentItem = 36955529;
};

// update code called every frame
BuildSystem.prototype.update = function(dt) {
    var camera = this.entity.findByName('Camera');
    var pointer = this.app.root.findByName('Pointer');
    
    // inorder to go to build mode
    if(this.InBuildMode === false && this.app.keyboard.wasPressed(pc.KEY_Z)){
        // enables
        this.InBuildMode = true;
        this.DisableCamera();
        this.app.mouse.disablePointerLock();
    }else if (this.app.keyboard.wasPressed(pc.KEY_Z)){
        // disables 
        this.InBuildMode = false;
        this.EnableCamera();
        this.app.mouse.enablePointerLock();
    
    }
    

    if(this.InBuildMode === true){
        // keys
        if(this.app.keyboard.wasPressed(pc.KEY_1)){
            this.CurrentItem = items[0];
            
        } 
        
        // rotation
        if(this.app.keyboard.isPressed(pc.KEY_Q)){
            pointer.rotate(0,5,0);
        }else if (this.app.keyboard.isPressed(pc.KEY_E)){
            pointer.rotate(0,-5,0);
        }
            
    }
    
    pointer.model.asset = this.CurrentItem;  
};

BuildSystem.prototype.onMove = function(event){

};

BuildSystem.prototype.onClick = function(){
    var a = this.app.root.findByName('Pointer').clone();
    this.app.root.addChild(a);
    
};

BuildSystem.prototype.DisableCamera = function(){
    var camera = this.entity.findByName('Camera');
    camera.script.cameraController.enabled = false;
    camera.setEulerAngles(-90,0,0);
    this.entity.rigidbody.enabled = false;
    this.entity.setPosition(this.entity.getPosition().x,40,this.entity.getPosition().z); 
};


BuildSystem.prototype.EnableCamera = function(){
    var camera = this.entity.findByName('Camera');
    camera.script.cameraController.enabled = true;
    this.entity.setPosition(this.entity.getPosition().x,1,this.entity.getPosition().z); 
    this.entity.rigidbody.enabled = true;
};



Thanks for replying… :no_mouth:

You seem to be creating a clone of the Pointer entity, is that on purpose?

yes

How do you know there isn’t a collision component on the clone?

when ever i run into the wall it doesnt collide with the player

Have you inspected the clone entity to check if a collision component is attached? Do you have a link to the project? Can you give the repo steps to show this bug too?

https://playcanvas.com/editor/scene/1004449

The radius is 0 for the collision component so there’s no volume:

im trying to do it with script because when you click a key it should swap the collision asset

At the moment, you are just cloning the pointer as is from the code you posted above so all the clones have a collision sphere of 0 radius

so the clones already have the same components. Thanks.