In my renderer delegate I create a raycast query from the center of the view to track estimated plane and display a 3D pointer that follows the raycast result.
It is done via view.raycastQuery(from:allowing:alignment:)
but is returns nil.
My question is why ? There is no documentation that says why this function would returns a nil value. I understand the raycast results could be empty, but why a query would not be created ?
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
guard view.session.currentFrame?.camera.trackingState == .normal else {
return
}
DispatchQueue.main.async {
let center = view.center
DispatchQueue.global(qos: .userInitiated).async {
if let query = view.raycastQuery(from: center, allowing: .estimatedPlane, alignment: .any) {
let results = view.session.raycast(query)
...
}
else {
// sometimes it gets here
}
}
}
}
There's no detected plane where ray hits
. But the raycast query should beraycast
-ed before knowing there are no detected hits (aka raycast results). You talk about results, I talk about query. Plus,sceneView.session.raycast(query!)
may crash due to force unwrap because query can be nil, which is what I want to know : why a query may be nil ? – Gout