Search code examples
swiftscenekitaugmented-realityarkit

Resetting ARKit coordinates


I have a simple question. If I wanted to start a game and place the board right in front of me:

gameBoard!.position = SCNVector3(0, 0, -0.6)

This works until I leave the game and come back again. Can I show the game board in exact same position in front of camera or 0.6m in front of me? I might have physically moved to another position.


Solution

  • If you want to reset you ARSession, you have to pause, remove all nodes and rerun your session by resetting tracking and removing anchors.

    I made a reset button that does it whenever i want to reset:

    @IBAction func reset(_ sender: Any) {
    
        sceneView.session.pause()
        sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in
            node.removeFromParentNode()
        }
        sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
    }
    

    Or put it in your session was interrupted function!