Search code examples
swiftsprite-kitsknode

children's children with enumerateChildNodes(withName:using:)


does enumerateChildNodes(withName:using:) go through and search the children of children, and their children, etc?

Or does it just search the first generation of children?

Docs are here, and mention nothing about this: https://developer.apple.com/reference/spritekit/sknode/1483024-enumeratechildnodes


Solution

  • That function is called on the parent to search it's children and that's it. It does not search the children of children. You would have to call that function on the children to search it's children.

    I've ran into issues with this before when I didn't know why a certain node with a name was not being found. It's because I had that node I was looking for was a child of another child.

    This Link to my Stack Overflow Question on why my node was not interacting with a certain node was because the node I wanted was not being found with enumerateChildNodes and I finally realized it at the very bottom in a comment.