Using Prefabs

The Unity Universal AR package contains prefab components for our ZapparCamera and various tracking types, such as: face tracking, image tracking, and instant tracking. These prefabs act as a template for the selected tracking type and any changes made to the prefab are reflected across all instances.

We also have a range of ready-made Unity example projects for you to download and play with. You can find them here.

Zappar Camera Prefab

All tracking types require the Zappar Camera Prefab component.

Once you've imported the package, the first step is to add the Zappar Camera prefab into your scene. Just drag it from your project's Assets/Resources/Prefabs folder into your scene's Hierarchy.

The resulting object is a regular Unity camera a component that makes the following changes:

  • its camera parameters (e.g. focal length) will be set automatically by the Zappar library to match those of the physical camera on your device
  • the physical camera feed will be drawn as a background to your scene
  • by default, the position of the camera is the origin of your scene, pointing down the Z axis. Objects that you track, e.g. the user's face, will move around in your scene so they appear in the correct location to the (stationary) camera.

Remove any other cameras you may have, or mark the Zappar Camera as your primary/active camera.

The camera object has a few properties you may like to change:

Property Description
Use Front-Facing Camera this causes the Zappar library to display the 'selfie' camera to the user (rather than the rear-facing camera) - useful for face filter experiences.
Camera Attitude From Gyro with this selected, the camera will remain at the origin of your scene, but rotate according to the device's orientation in 3D space. This means that your scene will remain flat with respect to gravity. This mode is useful if you have lighting effects or physics that require your scene to be aligned with the user's real-world environment.
Mirror Rear Cameras and Mirror User Cameras these options can be used to automatically mirror the camera background and 3D content. Users expect the content/image of user-facing cameras to be mirrored.
Anchor Origin if this is set to an instance of one of the tracking prefabs, that instance will become the origin of your scene. In this mode, the camera will move around that instance in 3D space (instead of remaining at the origin).


Image Tracker Prefab

The Image Tracker prefab lets you attach 3D content to an image. It's great for putting 3D content onto posters, business cards, flyers, etc. Once you've dragged the prefab into your hierarchy, you'll have to set the 'Target Filename' property to the 'target file' of the image you'd like to track. This file contains everything the Zappar library needs to detect and track the image in 3D space. You can generate them using the ZapWorks command-line utility like this:

zapworks train myImage.png

You can then import the resulting .zpt file into a folder named Assets/StreamingAssets in Unity.

You will need to create a StreamingAssets folder inside Assets if one doesn't exist.

Please note that you will have to manually drag and drop the .zpt file into the StreamingAssets folder, as Unity will not recognise it as a file type that can be imported using "Import New Asset". You can then set the Image Target ZPT property of the Image Tracking target to the name of this file. Note that this filename must match exactly what is on disk and can be inputted as a string or dragged into the input field.


Instant Tracker Prefab

Instant world tracking refers to the ability to attach content to a point in the world, without using a tracking image or marker. You do not need to specify any properties to use Instant World Tracking. Simply attach your content as a child of the ZapparInstantTracking GameObject and it will appear in the correct location. The Zappar Instant Tracker prefab will keep the content in front of the camera until the user taps on the screen, at which point the content will appear to remain anchored in place. You can override this tap and place behavior as you wish. Please refer to the Instant Tracking API section for further details.


Face Tracker Prefab

Dragging the Face Tracker prefab into your Hierarchy allows you to place 3D content that's tracked to the user's head. It's ideal for building face filter experiences where users wear AR hats, glasses etc. Once the prefab is in place in your Hierarchy, place 3D objects as children of that prefab for them to be tracked from the center of the user's head.


Face Mesh Prefab

The Zappar Face Mesh prefab provides a 3D mesh that fits with the user's face as their expression changes and their head moves. It exposes a Face Material parameter that can be set to any valid material (a UV map is provided that aids in development). Each of the Fill options determine whether or not the relevant portion of the mesh is 'filled' when it is rendered.

A Zappar Face Mesh requires a Zappar Face Tracker instance as its "Face Tracker" property (in the inspector). The Face Mesh can appear anywhere in the scene hierarchy, however, you should place it as a child of the Face Tracker if you wish for the mesh to appear correctly attached to the face.

Advanced Usage

The prefabs above are great for most use cases, and you may find they've got everything you need for your next AR project. That said, the Zappar library does provide a rich API that you can use should you require detailed control of the computer vision libraries.

zapcode branded_zapcode i