Face Filter AR App using
Unity ARFoundation
1. Introduction
This project demonstrates a simple Augmented Reality (AR) application
using Unity’s AR Foundation and ARCore/ARKit that tracks the user’s
face and overlays face filters (materials). The app enables users to
swap between di�erent filters by tapping a UI button.
2. Project Setup
2.1 Unity Environment
● Unity Version: (your version here, e.g., 2022.3.x LTS)
● Packages Used:
○ AR Foundation
○ ARKit XR Plugin (for iOS)
○ ARCore XR Plugin (for Android)
2.2 Scene Setup
1. Go to GameObject > XR > AR Session to add the session
manager.
2. Go to GameObject > XR > XR Origin (Mobile AR) to add tracking
support.
3. From GameObject > XR, add:
○ AR Default Face (for prefab)
○ AR Face Manager (component added to XR Origin)
4. Ensure the AR Camera Manager is configured:
○ Set Facing Direction to User (front-facing camera)
○ Enable Auto Focus
3. Implementation
3.1 Creating the Face Filter Script
Create a new C# script named SwapFace.cs and attach it to the XR
Origin or any GameObject holding the ARFaceManager.
public class SwapFace : MonoBehaviour
{
public Material[] faceMats;
int index = 0;
ARFaceManager faceManager;
void start()
{
faceManager = GetComponent<ARFaceManager>();
}
public void SwapFaceBtn()
{
foreach (ARFace face in faceManager.trackables)
{
face.GetComponent<Render>().material = faceMats[index];
}
index++;
if(index==faceMats.Length)
{
index=0;
}
}
}
3.2 Assigning Materials
1. Create or import various face materials (e.g., masks, e�ects).
2. In Unity, assign them to the faceMats array in the Inspector.
3. Assign AR Default Face prefab to the ARFaceManager’s Face
Prefab field.
3.3 Adding UI Button
1. Create a UI Button:
Go to GameObject → UI → Button
2. Set its OnClick event to trigger SwapFaceBtn() from the attached
script.
4. Build Settings
1. Go to File → Build Settings → Android/iOS
2. Click Switch Platform
3. Under Player Settings:
○ Enable ARCore/ARKit Support.
○ Set Minimum API Level to 24+ (Android) or iOS 13+
○ Set Camera Usage Description (iOS only)
4. Connect device and click Build and Run