Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.03k stars 1.13k forks source link

ARFaceManager ARFacesChangedEventArgs added and removed always 0 [Bug] #514

Closed yosun closed 3 years ago

yosun commented 4 years ago

Unity bug report case number Please log a bug at https://unity3d.com/unity/qa/bug-reporting and post the case number here.

Describe the bug When subscribed to ARFaceManager facesChanged action, it seems ARFacesChangedEventArgs added and removed always 0 even when a face is added or removed

To Reproduce Steps to reproduce the behavior:

  1. Modify the FaceMesh example
  2. Use this script. Make sure to assign arfm to the gameobject containing ARFaceManager
public class ARFaceSanityCounter:MonoBehaviour{
    public ARFaceManager arfm;

    void Start()
    {
        arfm.facesChanged += FaceChanged;
    }

    void FaceChanged( ARFacesChangedEventArgs fc )
    { 
        print("Added count "+fc.added.Count);
        print("Removed count " + fc.removed.Count);
    }
}
  1. Build to Xcode and look for "added" or "removed" ... try putting your face into the view. notice that the value remains 0. "added count 1" never occurs Removed also never updates

Expected behavior When a face is added or removed, fc.added.Count and fc.removed.Count should reflect non-zero numbers

Actual behavior When a face is added or removed, fc.added.Count and fc.removed.Count current maintains 0

Smartphone (please complete the following information):

DavidMohrhardt commented 4 years ago

ARKit Anchors typically are not removed until either explicitly removed (if user created) or the session is reset and in the ARKit plugin we only report an anchor as removed if it is no longer being reported by ARKit. In this case, ARKit maintains an understanding of the face even when the face itself isn't tracking. You can see this in ARFoundation by capturing the fc.updated list of ARFaces and checking the tracking state. When a face leaves the frame then the tracking state will report as None but ARKit will report the same face trackableId when that face moves back into frame.

DavidMohrhardt commented 4 years ago

Closing this issue. If you have more questions then please feel free to respond here.

tdmowrer commented 4 years ago

Hi @yosun - I had reopened this old issue because you claimed that fc.added.Count was never non-zero. That should not be the case, so I wanted to investigate. I tried to reproduce this in 2019.4 using the latest verified 2.1 packages (ARFoundation 2.1.8, ARKit 2.1.9, ARKit Face Tracking 1.0.7) with this script:

using UnityEngine;
using UnityEngine.XR.ARFoundation;

[RequireComponent(typeof(ARFaceManager))]
public class LogNumberOfFaces : MonoBehaviour
{
    void Start() => GetComponent<ARFaceManager>().facesChanged += OnFaceChanged;

    void OnFaceChanged(ARFacesChangedEventArgs eventArgs)
    {
        if (eventArgs.added.Count > 0)
        {
            Debug.Log($"{eventArgs.added.Count} faces added.");
        }
    }
}

As soon as my face is visible, the app prints "1 faces added." Unless it detects another face, it will not report an added face. Can you provide more details or a repro project? Or is this no longer an issue for you?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.