2

When I create an ArKit project on Xcode, the boilerplate project will not run and return an error that it cannot find the ship.scn asset.

Boiler-plate code for the SceneKit project:

    import UIKit
    import SceneKit
    import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet var sceneView: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the view's delegate
        sceneView.delegate = self
        
        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true
        
        // Create a new scene
        let scene = SCNScene(named: "art.scnassets/ship.scn")!
        
        // Set the scene to the view
        sceneView.scene = scene
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // Create a session configuration
        let configuration = ARWorldTrackingConfiguration()

        // Run the view's session
        sceneView.session.run(configuration)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        // Pause the view's session
        sceneView.session.pause()
    }

    // MARK: - ARSCNViewDelegate
    
/*
    // Override to create and configure nodes for anchors added to the view's session.
    func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
        let node = SCNNode()
     
        return node
    }
*/
    
    func session(_ session: ARSession, didFailWithError error: Error) {
        // Present an error message to the user
        
    }
    
    func sessionWasInterrupted(_ session: ARSession) {
        // Inform the user that the session has been interrupted, for example, by presenting an overlay
        
    }
    
    func sessionInterruptionEnded(_ session: ARSession) {
        // Reset tracking and/or remove existing anchors if consistent tracking is required
        
    }
}

Error: Fatal error: Unexpectedly found nil while unwrapping an Optional value: file

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value shows on following line: let scene = SCNScene(named: "art.scnassets/ship.scn")!

This was working for me previous to updating Xcode (current version is 13.0, Mac OS Big Sur Version 11.6).

Wondering why this could be happening, and how to get around this?

Ted.Mosby
  • 21
  • 3
  • 1
    Sometimes Apple removes stuff from XCode Template pool (i.Ex. Particle System Templates). Research on GitHub for any project containing the ship.scn. I am sure you will find one. Copy it from there and put it into your project (respecting the corect path in art.scnassets). This should run then. – ZAY Oct 05 '21 at 08:52
  • The weird thing was the ship.scn asset was available in the project, but until I took it out of the art.scnassets folder it wouldn't be found! – Ted.Mosby Oct 09 '21 at 22:25
  • That is indeed srtange... because usually the art.scnassets is the "good" location for such assets. – ZAY Oct 10 '21 at 07:49

1 Answers1

0

I spent so much time trying to solve this. It's a weird bug. But solution is actually really simple, just click on "art" folder and uncheck the "Prefer compressed textures". see the solution picture

You can even turn it on again, after running the app once, and it will work perfectly.