I'm trying to get the ARWorldTracking session to re-orient north after a session interruption. I've went over the documentation a few times but I'm finding it confusing.
Current Behavior:
When I lock the device and reopen the app, triggering the sessionWasInterrupted
, the SCNNodes all shift counterclockwise on the compass by ~90 degrees or so.
When you call the run(_:options:) method with a configuration of a different type than the session's current configuration, the session always resets tracking
I interpreted that as saying that when I generate a new set of configurations that is different from the viewWillAppear
, the session will "reset". I'm not getting what is actually happening, but the orientation after interruption is off. (and
removeExistingAnchors
does nothing)
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let configuration = ARWorldTrackingSessionConfiguration()
configuration.planeDetection = .horizontal
configuration.worldAlignment = .gravityAndHeading
sceneView.session.run(configuration)
}
func sessionWasInterrupted(_ session: ARSession) {
let configuration = ARWorldTrackingSessionConfiguration()
configuration.planeDetection = .horizontal
configuration.worldAlignment = .gravityAndHeading
self.sceneView.session.run(configuration, options: [ARSession.RunOptions.removeExistingAnchors, ARSession.RunOptions.resetTracking])
}
Desired Behavior:
When the app detects a session interruption, I'd like it to re-orient itself back to true north.
This issue was killing me, too - you helped me out with half the solution - adding the 'Reset tracking / Remove existing anchors' flags was the magic key for me - I think the other half is the guidance from This post where you have to pause your session and remove all the nodes from the scene, then re-position them. The combination of both of these things got the compass to reset back to True North after session interruption for me.
func resetARSession() {
// Called by sessionInterruptionDidEnd
sceneView.session.pause()
sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in
node.removeFromParentNode() }
setupARSession()
setupSceneView()
}
func setupARSession() {
let configuration = ARWorldTrackingConfiguration()
configuration.worldAlignment = .gravityAndHeading
sceneView.session.run(configuration, options: [ARSession.RunOptions.resetTracking, ARSession.RunOptions.removeExistingAnchors])
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With