Only the renderer nodeFor anchor isn't called in Swift Playgrounds

So basically the Delegation method of ARSCNViewDelegate :


// THIS METHOD AREN'T CALLED
    func renderer(_ renderer: SCNSceneRenderer,nodeFor anchor : ARAnchor) -> SCNNode? {
        guard let faceAnchor = anchor as? ARFaceAnchor,
            let device = MTLCreateSystemDefaultDevice() else {
                return nil
        }
        let faceGeometry = ARSCNFaceGeometry(device: device)
        let node = SCNNode(geometry: faceGeometry)
        node.geometry?.firstMaterial?.fillMode = .lines
        return node
    }


It isn't called on Swift Playgrounds. I'm using an iPad Pro 11 (with Truedepth frontal-camera). I tried to run the same code on Xcode, and I got it! But on Swift Playground I did not succeed.


I put this in viewDidLoad, viewWillAppear and viewWillDisappear:


     overridefunc viewDidLoad() {
        super.viewDidLoad()
        guard ARFaceTrackingConfiguration.isSupported else {
            fatalError("Face tracking is not supported on this device")
        }
        sceneView.delegate = self
        self.view = sceneView
    }
  
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let configuration = ARFaceTrackingConfiguration()
        configuration.isLightEstimationEnabled = true
        sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
    }
  
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        sceneView.session.pause()
    }


I need to call this function, but the method doesn't work.

Accepted Reply

Just to clarify,


The ARSCNViewDelegate methods are being called in Playgrounds, the issue lies specifically with the ARFaceTrackingConfiguration. It appears that Playgrounds is not getting access to the True Depth camera's depth data, which means that ARFaceTrackingConfiguration is never able to add an ARFaceAnchor, therefore that particular delegate method is never called. If you were using an ARWorldTrackingConfiguration, and had plane detection enabled, you would see that that particular delegate method is indeed being called.


I recommend that you file a bug report for this issue at https://developer.apple.com/bug-reporting/

Replies

Hey! I had the same problem, I solved it writing "public" before the function:

In addition, you can test if it's working clicking option button and in the function and see if the apple guide is appearing correctly

public    func renderer(_ renderer: SCNSceneRenderer,nodeFor anchor : ARAnchor) -> SCNNode? { 

Just to clarify,


The ARSCNViewDelegate methods are being called in Playgrounds, the issue lies specifically with the ARFaceTrackingConfiguration. It appears that Playgrounds is not getting access to the True Depth camera's depth data, which means that ARFaceTrackingConfiguration is never able to add an ARFaceAnchor, therefore that particular delegate method is never called. If you were using an ARWorldTrackingConfiguration, and had plane detection enabled, you would see that that particular delegate method is indeed being called.


I recommend that you file a bug report for this issue at https://developer.apple.com/bug-reporting/