Code not allowing user to change scn file (Swift4)

My code below places a dice multiples times. This is exactly what I want the code to doo. However when I change diceCollada.scn to another scn file that is in the assets folder. I don’t know why if I import another scn file I can not change the arkit object. All I want to do is to be able to use this exact code with another scn file that’s it.

      func addDice(atLocation location: ARHitTestResult) {

// Create a new scene

    ////IF I CHANGE diceCollada.scn to hat.scn THE OBJECT DOES NOT SHOW UP
let diceScene = SCNScene(named: "art.scnassets/diceCollada.scn")!

// Create Dice Node for Pos.

if let diceNode = diceScene.rootNode.childNode(withName: "Dice", recursively: true) {

    // Assign found position to dice
    diceNode.position = SCNVector3(
        location.worldTransform.columns.3.x,
        location.worldTransform.columns.3.y + diceNode.boundingSphere.radius,
        location.worldTransform.columns.3.z
    )

    diceArray.append(diceNode)

    // Set the scene to the view
    sceneView.scene.rootNode.addChildNode(diceNode)

    // Roll Dice
    roll(dice: diceNode)
}}

This line is looking for a node named “Dice” in the diceScene.

diceCollada.scn evidently has one. It sounds like hat.scn does not have one.

I tried

        let diceScene = SCNScene(named: "art.scnassets/dontCare.scn")!


   if let diceNode = diceScene.rootNode.childNode(withName: "Dont", recursively: true) {

it does not work the object still does not appear. I dont know why it is not working.

This topic was automatically closed after 166 days. New replies are no longer allowed.