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 facesChanged event is invoked with the relevant information.
Subscribe to the facesChanged
event by following these instructions:
Create a public method on a
MonoBehavior
orScriptableObject
with a single parameter of type ARFacesChangedEventArgs, as shown in the following example code:public void OnFacesChanged(ARFacesChangedEventArgs 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 } }
Use the following example code to subscribe to the
facesChanged
event:void SubscribeToFacesChanged() { // This is inefficient. You should re-use a saved reference instead. var manager = Object.FindObjectOfType<ARFaceManager>(); manager.facesChanged += OnFacesChanged; }