ArKit loses world orientation after switching from another view controller back to the ARSCNView

I have two ViewControllers one with the ARSCNView and one with just some data. When switching back from the second view controller to the first I can't get the ARSession to work right. It loses completely the orientation and can't detect the feature points correctly.


I already trief saving the world map and restoring it after the Back Button from one view to another is hit.

I also tried all the resetting stuff on the Session that is already provided on stack overflow

I do overwrite those methods:


override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // Pause the view's session
        sceneView.session.pause()
        print("view did disappear")
        sceneView.session.getCurrentWorldMap { (worldMap, error) in
            guard let worldMap = worldMap else {
                print("Error getting current world map.")
                return
            }

            do {
                try self.archive(worldMap: worldMap)
                DispatchQueue.main.async {
                    print("World map is saved.")
                }
            } catch {
                fatalError("Error saving world map: \(error.localizedDescription)")
            }
        }
    }

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let worldMapData = retrieveWorldMapData(from: worldMapURL)
        var worldMap: ARWorldMap? = nil
        if worldMapData != nil {
            worldMap = unarchive(worldMapData: worldMapData!)
        }
        resetTrackingConfiguration(with: worldMap)
    }

override func viewDidAppear(_ animated: Bool) {
      super.viewDidAppear(animated)
 }

 func resetTrackingConfiguration(with worldMap: ARWorldMap? = nil) {
     let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = [.horizontal]

    let options: ARSession.RunOptions = [.resetTracking, .removeExistingAnchors]
    if let worldMap = worldMap {
       configuration.initialWorldMap = worldMap
       print("Found saved world map.")
    } else {
       print("Move camera around to map your surrounding space.")
   }

    sceneView.debugOptions = [.showFeaturePoints, .showWireframe]
    sceneView.session.run(configuration, options: options
}

I just want my ARSession to work normal after hitting the back button of the UINavigation

Replies

Hello,


It is likely that the solution for this issue would be specific to your app, for that reason, I recommend that you file a techinical support incident for this issue at https://developer.apple.com/support/technical/