Area Targets in Unity

This guide will take you through the process of importing and working with Area Targets in Unity. By importing the Unity package that is created in the Area Target Generator you will be able to design and develop environment-based AR experiences for Unity’s supported platforms.

A sample Area Target database is not included in the Vuforia Core Samples. You will need to create and use your own Area Target. Please consult the guides on the Best Practices for Preparing and Scanning an Environment and How to create an Area Target to learn more on creating Area Targets. Additionally, Area Targets is only supported on iOS device capable of running ARKit, Android devices capable of running ARCore, and the Microsoft HoloLens devices.

Creating your Area Target Unity Project

If you have your own Area Target ready and at hand as a *.unitypackage you can start the following steps.

  1. Start by creating and opening a new project in Unity 2019.2 or newer.
  2. Set up your project with Vuforia Engine by adding the Vuforia registry. See here on how to do this.
  3. Remove the default Main Camera from the scene. Replace it with an ARCamera by going to the GameObject menu -> Vuforia Engine -> AR Camera.
  4. Obtain a License Key for your project. Please refer to the Vuforia License Manager guide on how to obtain a license key.
    1. Place your license key in the associated field under Vuforia Configuration.
    2. Enable the Device Tracker at the same time.

NOTE: Enabling the Device Tracker is required when using Area Targets.

Scene Set-up with Area Targets

  1. Create an AreaTarget GameObject from the GameObject drop down menu -> Vuforia Engine and then select Area Target.
area-target-unity-gameobject
  1. Proceed to import the Area Target database *.unitypackage that was generated from the Area Target Generator by selecting Assets-> Import Package -> Custom Package.
  2. In the inspector window of the AreaTarget GameObject, add the imported database and Area Target via the dropdown menu.

Configuring the Area Target

The Area Target database contains additional assets of the scanned area including textures, materials, and a prefab model. After importing the package, from the Project window, locate these files in the folder Editor -> Vuforia -> <dataset name> folder. The preview mesh of the scanned area is added automatically to the AreaTarget GameObject but a prefab model can also be placed in the scene if you wish to modify certain captured elements of the area.

NOTE: Changing the size of the AreaTarget GameObject is not supported. This guarantees that your scanned real environment retains its original scale throughout the entire development toolchain. If you need to use a different scene scale in your project, please review the Virtual Scene Scale Factor in Unity article.

In Unity, you can enable occlusion on your real environment. By ticking the box for Simulate Occlusion, your preview mesh hides the content that is obstructed by the environment’s walls and doors when used in PlayMode. If you wish to test your Area Target while being able to see all your content, you can untick the box.

  • Select your AreaTarget GameObject and in the Area Target Behaviour component, click the Advanced dropdown. Here you may choose to have Simulate Occlusion enabled or disabled.
area-target-behaviour-component-unity
  • Add a 3D Object Cube or your own content to the scene and position it in relation to the preview model, matching the scale of the environment. Add your augmentation content as a child to the AreaTarget GameObject.

NOTE: It is possible to add other Vuforia targets to your project such as a Model Target to improve tracking around an object that is central for the augmented user experience.

unity-scene-area-target-hierarchy

Add the Preview Model of your scanned area to your scene to add additional effects.

  • Add an occlusion shader on the preview model to selectively hide content behind walls or doors.
  • Use raycasting with a mesh collider to let users place augmented content at runtime.
  • Add a navigation mesh to your scene to guide users around. See NavMesh in Unity on how to do this.

Preview your Area Targets in Simulation Mode

For an introduction to Simulator mode in Unity, please see Vuforia Play Mode in Unity.

Test your Area Target project with the Simulator mode located in Vuforia Configuration under Play Mode. Set up your preferences for Walking Speed and Key Bindings and press the Play button. This allows you to navigate through your environment, providing you with a full preview of your built to test your effects and interactive components.

unity-area-targets-in-vuforia-simulator-mode

Build your Unity Project

When ready, you can build your Unity Project to your ARCore or ARKit supported device or to a HoloLens device for testing at site. A Vuforia project is built in the same way as other Unity apps for Android, iOS, and UWP platforms.

Learn More

Vuforia Play Mode in Unity

Using Unity's NaVMesh for Navigation with Area Targets

Best Practices for Preparing and Scanning an Environment

How to create an Area Target

Virtual Scene Scale Factor in Unity