Hi, I'm relatively new to Swift and ARKit, SceneKit and the likes of which you'd use for typical AR applications.
TL;DR, I have an app with a reset button that pauses the sceneView, deletes all child nodes of the root node of sceneView.scene, and re-runs my overridden version of viewWillAppear! However, after this reset, my app refuses to detect my anchors (.arobject scan assets) in the scene. Any help would be much appreciated.
I did read up on the documentation and relevant forum & SO posts and provide my code and a list of things I tried down below.
my overridden viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Models occluded by people are shown correctly
if #available(iOS 13.0, *) {
print("Segmentation with depth working!")
ARWorldTrackingConfiguration.supportsFrameSemantics(.personSegmentationWithDepth)
} else {
// Fallback on earlier versions
}
guard let referenceObjects = ARReferenceObject.referenceObjects(inGroupNamed: "computer", bundle: nil) else {
fatalError("Missing expected asset catalog resources.")
}
configuration.detectionObjects = referenceObjects
print(configuration.detectionObjects)
sceneView.session.run(configuration)
}
my custom reset function
@IBAction func reset(_ sender: UIButton!) {
// Pause scene view
sceneView.session.pause()
// Remove button that redirects to link
DispatchQueue.main.async {
self.sceneView.subviews[1].isHidden = true
}
// Remove all child nodes
sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in
node.removeFromParentNode()
}
viewWillAppear(true)
}
list of things I tried
- put everything into viewWillAppear and just trigger viewWillAppear on button press
- call the custom reset function shown above on button press
- call overridden viewDidLoad (yes, I know this is *****, but I wanted to see if it fixed anything)
Currently, my code is using the second setup from the list above.