[SOLVED] Removing and adding during swap not removing

I’m trying to take advantage of the swap function, but it doesnt seem to be removing the objects to reset the scene. Am I misusing removeChild?

source https://github.com/bit-garden/bit-garden.github.io/blob/master/rps/assets/scripts/game.js

If you want to completely remove the entities, try the destroy function:

old.boxes.forEach((e)=>{
    e.destroy ();
});

works as expected. In this case either will work effectivly, but why does remove child not work as anticipated?

Looks like you’ve change the code, but assuming you’ve just replaced removeChild with destroy then I think the reason it didn’t work for you is that removeChild doesn’t remove the model from the scene it just removes it from the hierarchy.

Other options you have are:

entity.destroy() which removes the entity and destroys all components
entity.enabled = false this disables the entity, stops it updating and removes it from the scene.
entity.model.hide() leave entity enabled and leave model in scene, but prevent it rendering.

Suggested way by @BenBean303 uses arrow functions, which are not supported eveywhere. Better to use classic for(var i loop or normal anonymous function in forEach.

Ah that would do it. Thank you again.