# Delegate not working

**URL:** <https://forum.deepar.ai/t/delegate-not-working/547>\
**Category:** Help & Questions\
**Created:** [January 27, 2024, 6:30pm UTC](https://forum.deepar.ai/t/delegate-not-working/547 "2024-01-27T18:30:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcovise](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@marcovise](https://forum.deepar.ai/u/marcovise)\
**Post date:** [January 27, 2024, 6:30pm UTC](https://forum.deepar.ai/t/delegate-not-working/547/1 "2024-01-27T18:30:06Z")

</div>

Hello everybody, I am new in DeepAR. I wrote this simple code where I am trying to print the value of some landmarks and I am using the MVVM design. Could anybody help me understanding why once the model.deepAR.delegate = self line is run (I get the print on the terminal) the faceTracked function is never called (I can’t see the print on terminal) when I run the app and my face is clearly visible?

```auto
import SwiftUI
import DeepAR

struct ContentView: View {
    @ObservedObject var arViewModel = DeepARViewModel()
    
    var body: some View {
        DeepARViewContainer(arViewModel: arViewModel)
                    .edgesIgnoringSafeArea(.all)
    }
}

struct DeepARViewContainer: UIViewRepresentable {
    var arViewModel: DeepARViewModel

    func makeUIView(context: Context) -> UIView {
        arViewModel.startSessionDelegate()
        return arViewModel.arView
    }

    func updateUIView(_ uiView: UIView, context: Context) {
        // Update the view if needed
    }
}

struct DeepARModel {
    // Your DeepAR logic here
    var deepAR: DeepAR!
    private var cameraController: CameraController!
    var arView: UIView!
    var lefMouthLandmark: Float = 0
    var rightMouthLandmark: Float = 0

    init() {
        // Initialize and configure DeepARView
        deepAR = DeepAR()
        deepAR.setLicenseKey("my_key")
        cameraController = CameraController()
        cameraController.deepAR = deepAR
        arView = deepAR.createARView(withFrame: UIScreen.main.bounds)
        cameraController.startCamera()
    }
    
    mutating func update(multiFaceData: MultiFaceData) -> Void {
        self.lefMouthLandmark = Float(multiFaceData.faceData.1.landmarks.55)
        self.rightMouthLandmark = Float(multiFaceData.faceData.1.landmarks.49)
        print(self.lefMouthLandmark)
        print(self.rightMouthLandmark)
        }
    }

class DeepARViewModel: UIViewController, ObservableObject {
    @Published private var model : DeepARModel = DeepARModel()
    
    var arView : UIView {
        model.arView
    }
    
    func startSessionDelegate() {
        print("Session delegate on")
        model.deepAR.delegate = self
    }
    
    }
    

extension DeepARViewModel: DeepARDelegate {
    func faceTracked(_ faceData: MultiFaceData) {
            print("In the face Tracked")
            model.update(multiFaceData: faceData)
        }
}

```

---

<div class="post-metadata">

**Author:** ![marcovise](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@marcovise](https://forum.deepar.ai/u/marcovise)\
**Post date:** [January 28, 2024, 7:04pm UTC](https://forum.deepar.ai/t/delegate-not-working/547/2 "2024-01-28T19:04:29Z")

</div>

Update: I still have the same issue but the reason seems to be that the face tracking is not active unless there’s some event (like a face filter) that triggers it. For this reason I activated the face tracking as soon as the Deep AR engine is initiated and I did that before creating any ARView as suggested in the documentation. This is the updated init() of DeepARModel.

```auto
    init() {
        // Initialize and configure DeepARView
        deepAR = DeepAR()
        deepAR.setLicenseKey("my_key")
        faceTrackingInitParameters = FaceTrackingInitParameters(initializeEngineWithFaceTracking: true, initializeFaceTrackingSynchronously: true)
        deepAR.setFaceTrackingInitParameters(faceTrackingInitParameters)
        
        cameraController = CameraController()
        cameraController.deepAR = deepAR
        arView = deepAR.createARView(withFrame: UIScreen.main.bounds)
        cameraController.startCamera()
        print("Is face visible: ", deepAR.faceVisible)
    }

```

This doesn’t work. It prints “Is face visible : false”. (And of course when I try the app on my phone my face is clearly visible)

---

<div class="post-metadata">

**Author:** ![jelena](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jelena/32/14_2.png) [@jelena](https://forum.deepar.ai/u/jelena)\
**Post date:** [January 30, 2024, 8:05am UTC](https://forum.deepar.ai/t/delegate-not-working/547/3 "2024-01-30T08:05:57Z")

</div>

[emptyeffect.deepar.zip](https://forum.deepar.ai/uploads/short-url/9phYrp2wC4vsol1KJ4vR8fh2dsW.zip) (656 Bytes)  
Hi,

Yes the face tracking isn’t called in a frame if no active effect uses it. The workaround is simple, just call switch effect with the effect I’ve attached. It makes no visual change, it simply forces the face tracking to be active

---

<div class="post-metadata">

**Author:** ![marcovise](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@marcovise](https://forum.deepar.ai/u/marcovise)\
**Post date:** [January 31, 2024, 12:19am UTC](https://forum.deepar.ai/t/delegate-not-working/547/4 "2024-01-31T00:19:47Z")

</div>

Thank you very much Jelena it worked. A quick, follow up question. I am trying to detect a smile before the filter is applied. I tried to do that using landmarks but even if I managed to get the X, Y coordinates of the mouth corners they vary a lot depending on things like distance from the camera so it’s really hard to hard-code the conditions for a smile based on those values. As an alternative I could use an empty emotion filter to activate the emotion detection and use a threshold on ‘happiness’. Is it possible to create an empty emotion filter? Is it the best solution according to you? Thanks!

---

<div class="post-metadata">

**Author:** ![jelena](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jelena/32/14_2.png) [@jelena](https://forum.deepar.ai/u/jelena)\
**Post date:** [January 31, 2024, 5:41pm UTC](https://forum.deepar.ai/t/delegate-not-working/547/5 "2024-01-31T17:41:52Z")

</div>

Yes, loading an invisible emotion effect would be the solution. Which effect do you use for emotions?

Disabling the mesh renderers should be enough

---

<div class="post-metadata">

**Author:** ![marcovise](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@marcovise](https://forum.deepar.ai/u/marcovise)\
**Post date:** [February 1, 2024, 9:34am UTC](https://forum.deepar.ai/t/delegate-not-working/547/6 "2024-02-01T09:34:09Z")

</div>

Thanks again Jelena! I am currently trying to build one. Do you happen to have any emotion filter off-the-shelf to provide?

---

<div class="post-metadata">

**Author:** ![jelena](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jelena/32/14_2.png) [@jelena](https://forum.deepar.ai/u/jelena)\
**Post date:** [February 1, 2024, 4:15pm UTC](https://forum.deepar.ai/t/delegate-not-working/547/7 "2024-02-01T16:15:44Z")

</div>

[InvisibleEmotions.deepar.zip](https://forum.deepar.ai/uploads/short-url/yUZh6drCQjUv8Bdl5ock0YZqJr1.zip) (1.9 KB)

I made this one, it should work.

---

<div class="post-metadata">

**Author:** ![marcovise](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@marcovise](https://forum.deepar.ai/u/marcovise)\
**Post date:** [February 1, 2024, 5:52pm UTC](https://forum.deepar.ai/t/delegate-not-working/547/8 "2024-02-01T17:52:46Z")

</div>

Legend! Thank you so much!
