When SCNScene(named: "art.scnassets/diceCollada.scn")
is called, an error occurs when returning nil. The same is true if you put the ship.scn
file provided by Apple as a sample as a (named:)
parameter. I just don’t know what’s wrong.
guard let diceScene = SCNScene(named: "art.scnassets/diceCollada.scn")
else { fatalError("Unable to load scene file.") }
if let diceNode = diceScene.rootNode.childNode(withName: "Dice",
recursively: true) {
diceNode.position = SCNVector3(x: 0, y: 0, z: -0.1)
sceneView.scene.rootNode.addChildNode(diceNode)
}
I expected the "diceCollada.scn" object to appear on the ar screen on the app screen, but an error occurred when I called SCNScene(named: "art.scnassets/diceCollada.scn")
.
2
Answers
As @ZAY said in the comment it might be corrupted if you cannot open the file with the Xcode editor. So otherwise, I recommend you to open the file with REALITY COMPOSER (Which is in the developer app of the Xcode).
There is the possibility of a file direction problem. So check the direction of the file. Ensure the file and direction folder are checked as your bundle’s target.
Try moving the
.scn
and.png
files from theart.scnassets
folder to the root directory of Xcode’s Navigation pane. If this doesn’t help, then your SceneKit’s scene may be damaged or corrupted, or the file’s name is misspelled.Also make sure you checked the
Add to targets
box when you loaded the file into the project.