Remove the focus point when the camera sees ARImageAnchor and reveal the focus point when the camera does not see ARImageAnchor

I try to obtain focus point entity when camera not see ARImageAnchor, and remove after camera sees ARImageAnchor, and when camera not sees anchor obtain focus point again. I used arView.session.delegate, but delegate method maybe call one time, i don't know. how to make it? Thank u


  var focusEntity: FocusEntity! // (FocusEntity: Entity, HasAnchoring) 

  override func viewDidLoad() {
        super.viewDidLoad()
        // ...
        focusEntity = FocusEntity(on: arView, style: .classic(color: .systemGray4))
        arView.session.delegate = self
    }
}


extension CameraViewController: ARSessionDelegate {
    func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
        for anchor in anchors {
            if let imageAnchor = anchor as? ARImageAnchor {
                focusEntity.destroy()
                focusEntity = nil

                //... Obtain entity to image anchor
            }
        }
    }

    func session(_ session: ARSession, didUpdate frame: ARFrame) {
        //... ???
    }
}

Funny that I have the same question, tried everything and cannot get the focusEntity away :)

You can show and hide a RealityKit entity with the isEnabled property. To make this dependent on the anchor's visibility, you can use its isTracked property.

Remove the focus point when the camera sees ARImageAnchor and reveal the focus point when the camera does not see ARImageAnchor
 
 
Q