Search code examples
iosarkitsknodearanchor

How to pin multiple SKNodes on one ARAnchor?


I came across an obstacle during my ARkit project that use ARSKView.

I want to achive when use tap on the screen and an ARAnchor is created, multiple SKNodes will pop up from the same anchor. Since I will need to interact with each of the node individually,

By default I see that form the func view there is only one output of SKnode.

func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode?

I am very new to ARKit, and even Swift 4 so I would like your guidence. Please let me know if there is anything else that I need to clarify.

Thank you


Solution

  • From pretty early in the SKNode documentation:

    Nodes are organized hierarchically into node trees, similar to how views and subviews work

    Anywhere in SpriteKit (as used together with ARKit or otherwise) where you can use one SKNode (or node subclass), you can use multiple nodes by adding them as children of one node. See "Creating the Node Tree" in the aforelinked doc, the addChild(_:) method, etc.