Unity with AR Foundation is introducing more and more features from Google ARCore and Apple ARKit. One such feature is face tracking, which is luckily really easy to set up!
At the time of writing this post, I had to use Unity 2019.2. Unity 2019.3.0f6 was making weird builds that didn’t work on iOS. ?♂️
I hope they fix that shortly! ?
In a mean-time, let’s create a new project!
Setup project ??
The project setup is similar to what we did in the previous AR post.
First, we need to open the Package Manager and install the AR Foundation and ARKit Face Tracking packages. The rest of the packages will install automatically.
Build AR scene ??
The next step is to prepare the scene with AR elements. With AR Foundation, we already have all the necessary components.
First, we need to create AR Session in the scene.
Second, we also have to create AR Session Origin in the scene.
Awesome! We are almost done!
Face Tracking ?
With the scene almost ready, now it’s time to add face tracking!
Unity provides us with some default face to use. Let’s create one in the scene!
And as we have it there, let’s create a prefab of it! We will need it do make face tracking work.
With the prefab, now we can add AR Face Manager to the AR Session Origin and set it up with our face prefab.
In the end, our whole scene hierarchy should have four objects.
Build settings ?
Before building the project on your device, you have to adjust a few Player settings.
Face tracking was introduced with the first version of ARKit, but if you want to be able to detect more faces, you have to use ARKit 3. This also means that you are forced to use at least iOS 13.0 in the build settings.
Also, you have to change the build architecture to ARM64 as it’s the only one supported for these features, and Universal is already deprecated.
If you set everything, now it’s time to make a build!
The result ?
Roll the drums! ?
You got shreked! I mean, by default, our AR Face has green material, so you will look like Shrek! ?
But if this is working, you have an option to work further with the project!
What do you think about it? Do you find this useful? Let me know in the comment section below or share it with your friend! I would really appreciate that! ❤️
And if you are interested in getting emails when I release new post sign up for the newsletter!
You can also check the whole project at my public repository. ?
See you next time! ?