[ANSWERED] Is it safe to call removeFromParent() in the middle of a breadthFirstTraversal?

Is it safe to call removeFromParent() in the middle of a breadthFirstTraversal? And if so, how does it behave? Ideally, I’d like to be able to remove a Node and then not visit any of its children.

A few clicks away on the web. One click away in the SDK:

As you can see, it visits before it traverses but traversing happens whether you’ve removed it or not.

What is it that you are actually trying to do? The requirement is a bit strange.

1 Like

You can see more of what I’m trying to do in this thread. Solving that problem might make this irrelevant:

For this you can make your own utilities. ie (with a depth traversal):

    public interface Operation {
        
        /**
         * Must stop that branch
         * @return 
         */
        public boolean operate(Spatial spatial);
    }

    public static <T extends Operation> T visitNodeWith(Spatial spatial, T operation) {
        if(!operation.operate(spatial)) {
            if(spatial instanceof Node) {
                for(Spatial s : ((Node)spatial).getChildren()) {
                    visitNodeWith(s, operation);
                }
            }
        }

        return operation;
    }