[SOLVED] Can't enable Clone if the entity it's cloned from is not enabled

here I have made a simple scene, where ‘Entity’ holds a script which is
image

where this.box refers to an entity in the scene, the expected output is console.log(this.clone.enabled); would return true, but as seen here

It does not return the expected output, and I am kinda stuck here

Hello @agent178 ,

That is happening because your cloned entity doesn’t have a parent entity yet. Thus it’s not showing in your scene. A simple console.log(this.clone.parent) will show you what’s going on.

Try and add your cloned entity to a parent before enabling it! Here a simple code example:

Clone.prototype.initialize = function() {
 
    this.parentBox.enabled = false;

    this.clone = this.box.clone();
    this.entity.addChild(this.clone);
    this.clone.enabled = true;

    console.log(this.clone.enabled);

};

1 Like

Thanks!!!, Weird because i never needed to reparent it before.
My old code stopped working and i didn’t know why :grin:

1 Like

You have to add the clone to the hierarchy somehow. For example, you can also use the method below.

this.app.root.addChild(this.clone);