I need to remove all the CSS2DObject from my scene with below code it removes only first object then displays an error in traverse
scene.traverse(function(child){
if(child instanceof CSS2DObject){
scene.remove(child);
}
})
what is the proper way to remove all CSS2DObject from scene
scene.children.forEach(function(){
console.log(scene.children);
if(scene.children instanceof CSS2DObject){
scene.remove(scene.children);
}
})
I tried this code also but didn’t work is this right way?
Try making an array of objects to remove, then do the removing outside of the scene object
const toremove = [ ];
scene.traverse(function(child){
if(child instanceof CSS2DObject){
toremove.push(child)
}
});
toremove.forEach(child => scene.remove(child));
2 Likes