So I am developing an AR application. I have a button that initiates a exam/test mode where use has to answer questions correctly and gains one mark for each correct answer. When the test mode is initiated a pointOfView node from the defaultCameraController is used and the score is displayed on the ARSCN. Ending the test removes the node from the screen. However, after I click on the test button again in the same session, the code gets called, however it does not appear on the screen. The code for the start test button, stop test button and the setup scoreboard function are shown below. Excuse the clutter. I have to organise the code after fixing the functionality.
@IBAction func testButton(_ sender: Any) {
if sceneView.scene.rootNode.childNodes.count > 0{
testScore = 0
learningModeEnabled = false
learningMode.isEnabled = false
for nodePos in nodePositions{
// Create 3D Text
}
startTestButton.isHidden = true
stopTestButton.isHidden = false
//--------------------------------------------------------------------------
setupScoreboard()}
else{
print("No Nodes Detected in Environment")
}
}
@IBOutlet weak var stopTestButton: PressableButton!
@IBAction func stopTestButton(_ sender: Any) {
nodePositions = [:]
sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in
node.removeFromParentNode()
}
stopTestButton.isHidden = true
startTestButton.isHidden = false
let userDefaults = UserDefaults.standard
userDefaults.setValue(testScore, forKey: "score")
userDefaults.synchronize()
//--------------------------------------------------------------------------
self.sceneView.defaultCameraController.pointOfView?.enumerateChildNodes({ (node, stop) in
node.removeFromParentNode()
})
if userDefaults.data(forKey: "score") != nil{
userScores = userDefaults.array(forKey: "score") as! [Int]
print(userScores)
}
}
//--------------------------------------------------------------------------
func setupScoreboard(){
self.sceneView.defaultCameraController.pointOfView?.enumerateChildNodes({ (node, stop) in
node.removeFromParentNode()
})
let worldCoord : SCNVector3 = (self.sceneView.defaultCameraController.pointOfView?.position)!
let node : SCNNode = self.createNewBubbleParentNode("Score: \(String(testScore))")
node.position = SCNVector3( 0, 0.3, -1)
node.name = "Scoreboard"
self.sceneView.defaultCameraController.pointOfView?.addChildNode(node)
}
Edit: Added Comment lines near code relevant to question.