How can I remove all nodes from a scenekit scene?

Tim Andrews picture Tim Andrews · Feb 26, 2015 · Viewed 16k times · Source

Hi I am trying to remove all nodes from my Scenekit scene but I cannot for the life of me figure out a way.

It seems logical to me that there must be a function for doing this automatically but I cannot find it.

In context, I am trying to remove all nodes so I can reset my scene, which will happen reasonably often. Perhaps there is another way of doing this and I would be fine with that, I'm not stuck with having to remove all nodes.

Thanks!

Answer

Alan picture Alan · Jun 4, 2015

Try this (assuming you are using Swift):

rootNode.enumerateChildNodes { (node, stop) in
        node.removeFromParentNode()
    }

Works for me.