AR Face Manager component
The ARFaceManager component is a type of trackable manager that detects and tracks human faces in the physical environment. As a trackable manager, the AR Face Manager creates GameObjects in your scene for each detected face.
AR Face Manager component
Property | Description |
---|---|
trackables Changed | Invoked when trackables have changed (been added, updated, or removed). |
Face Prefab | If not null , this prefab is instantiated for each detected face. If the prefab does not contain an AR Face component, ARFaceManager will add one. |
Maximum Face Count | The maximum number of faces to track simultaneously. |
Get started
Add an AR Face Manager component to your XR Origin GameObject to enable face tracking in your app. If your scene doesn't contain an XR Origin GameObject, first follow the Scene setup instructions.
Whenever your app doesn't need face tracking functionality, disable the AR Face Manager component to disable face tracking, which can improve app performance. If the user's device doesn't support face tracking, the AR Face Manager component will disable itself during OnEnable
.
Respond to detected faces
While enabled, the AR Face Manager component will get changes reported by the XRFaceSubsystem every frame. If any faces were added, updated, or removed, the trackablesChanged event is invoked with the relevant information.
When a face is detected, a GameObject is instantiated with an attached ARFace
component, which contains data about the detected face. Refer to AR Face component to learn more about the trackable life cycle.
You can subscribe to trackablesChanged
in one of two ways:
Use the Inspector
a. Create a public method on a
MonoBehavior
orScriptableObject
with a single parameter of type ARTrackablesChangedEventArgs<ARFace>, as shown in the following example code:public void OnTrackablesChanged(ARTrackablesChangedEventArgs<ARFace> changes) { foreach (var face in changes.added) { // handle added faces } foreach (var face in changes.updated) { // handle updated faces } foreach (var face in changes.removed) { // handle removed faces } }
b. Select your XR Origin GameObject, then click the Add (+) button on the AR Face Manger component's trackablesChanged property.
c. Using the Object picker (⊙), select either a GameObject that contains an instance of your component or an instance of your ScriptableObject, whichever is applicable.
Subscribe to the trackablesChanged eventd. In the dropdown, select your class name and the name of your method. The method name appears in the Dynamic section of the methods list.
Use C# scripting
a. Create a public method with a single parameter of type ARTrackablesChangedEventArgs<Face> as shown in step 1a.
b. Use the following example code to subscribe to the
trackablesChanged
event:void SubscribeToFacesChanged() { // This is inefficient. You should re-use a saved reference instead. var manager = Object.FindAnyObjectByType<ARFaceManager>(); manager.trackablesChanged.AddListener(OnTrackablesChanged); }