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 from 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 as a runtime feature are 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 begin with the following steps.

  1. Start by creating and opening a new project in Unity. For supported Unity Editor versions, see Supported Versions.
  2. Set up your project with Vuforia Engine by adding the Vuforia Engine SDK. 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 (CmD+Shift+V for macOS, Ctrl+Shift+V for Windows)
  5. If it isn’t already, 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 GameObject->Vuforia Engine->Area Target.

  1. Proceed to import the Area Target database *.unitypackage that was generated from the Area Target Generator by selecting Assets-> Import Package -> Custom Package (or double click the *.unitypackage).
  2. Select the AreaTarget GameObject and the imported database and Area Target via the dropdown menu.

Legacy Area Targets

With the release of Vuforia Engine 9.7, earlier generations of Area Targets databases are subject to a compatibility issue. If you have imported your Area Target .unitypackage, and you see the below message either in the log or in the inspector panel of the Area Target, you will need to apply some additional steps to unlock its full capabilities. Legacy Area Targets are essentially no longer supporting occlusion mesh and mesh colliders.

"Legacy Area Target Warning: 
The target 'targetName' was generated with a tool before Vuforia 9.7. 
Occlusion Mesh and Mesh Collider are not available automatically. Check documentation for manual steps to resolve."

Options to resolve the legacy Area Target warning:

  • To use your existing legacy Area Target go to the Unity Migration Guide and follow the steps to manually configure colliders and occlusion meshes.
  • Re-generate your Area Target with the latest Area Target Generator. See How to Create Area Targets.
  • If you are using the Area Target Creator app; re-capture your space and generate a new Area Target database from it.

Configuring the Area Target

The Area Target database contains additional assets of the scanned area including textures, materials, and a prefab model or mesh. After importing the package, from the Project window, locate these files in the folder Assets/Editor/Vuforia/<dataset name> folder.

The preview mesh of the scanned area is added automatically to the AreaTarget GameObject but a prefab model from Matterport™ generated Area Targets is available and can 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, it is always in ‘meters’. It guarantees that your scanned 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.

Occlusion

In Unity, you can enable occlusion on your real environment. By ticking the box for Add Occlusion Mesh in the Area Target Behaviour component, the content that is obstructed by the environment’s walls and objects will be realistically be obstructed. If you wish to test your Area Target while being able to see all your content, you can keep the box unticked.

NOTE: There aren’t any preview meshes for point clouds as it is the case with Area Targets generated from meshes. But the occlusion mesh is supported.

  • Select your AreaTarget GameObject and in the Area Target Behaviour component, click the Advanced dropdown. Here you may choose to have Add Occlusion Mesh enabled or disabled.
  • Enable the Add Mesh Collider option to be able to ray-cast against the mesh representation of your environment, or include the environment into collision and physics simulations.

Point Cloud Area Targets will only support colliders for the closest surroundings during runtime.

  • 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.

Here are some suggestions for additional configurations of the Area Target GameObject :

  • Add a custom 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.
  • Prepare multiple Area Targets in a single scene for seamless transition and tracking into new areas.
  • Use AreaTargetBehaviour to provide access to AreaTarget functionality at runtime. In most cases, you call methods using the AreaTargetBehaviour class with BoundingBox() for the target’s bounding box in 3D scene units, and Size() to get the dimensions of the physical target.

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 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. Simulator mode allows you to navigate through your environment, providing you with a full preview of your scene and chance to test your effects and interactive components.

 

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 on the site. A Vuforia project is built in the same way as other Unity apps for Android, iOS, and UWP platforms.