A box that don't detach from the scene

Hello,

Im a bit embarrassed to post for such a little problem, but I can’t find a solution.
I made a control class for boxes. I want the box to detach when a condition is met.
I get the node with a getter, and then do node.detachChild(spatial);
This doesn’t work. If I do node.detachAllChildren(), it works as expected.

Thank you in advance.

Post code or nobody can help you.I think that “spatial” is not the node that you want to detach,but i can’t be sure if i don’t see the code.

I would agree with aegroto, although it could be the wrong node that you’re trying to detach from. For instance if you have rootNode → node → box and you try to do rootNode.detachChild(box) it won’t work, you would need to do rootNode.detachChild(node) or node.detachChild(box). Or you could just do:

box.removeFromParent();

Thank you both. removeFromParent() worked. So I tried getParent() and it printed “null”. It was indeed a mistake in my code. Definitively embarassed :stuck_out_tongue:

Glad you got it fixed up! Nothing to be embarrassed about, mistakes are so common in coding they have their own name, bugs :beetle:

Read an article not that long ago that suggested if it weren’t for bugs many programmers might find themselves out of a job since so much time is spent doing little more than fixing them.