Introduction to Model Targets in Unity

This guide walks you through the process of placing AR content onto physical objects using Model Targets. For an optimal tracking experience, we recommend using Model Targets in conjunction with Device Tracking.  

Creating your first Model Target Experience

  1. Create a new Unity project.
  2. Add the Vuforia Engine package to your Unity project as explained in this article
  3. Remove the default Main Camera from the scene. Replace the default Main Camera with an ARCamera from GameObject -> 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 Vuforia Engine license key.

NOTE: A license key is not necessary when using the Vuforia Sample package with the NASA Viking Lander model. See this article on how to obtain the NASA Viking Lander model and its 3D printing instructions.

NOTE: Device tracking is enabled by default. It is recommended to use device tracking with Model Targets.

  1. If you haven't already done so, generate a Model Target database using the Model Target Generator. You will be importing the *.unitypackage file generated from the MTG tool
  2. Import the Model Target from Assets -> Import Package -> Custom Package… and select the *.unitypackage file
  • Alternatively, a default Model Target database can be imported by creating a ModelTarget GameObject before importing a database. Right-click in the Hierarchy and select GameObject -> Vuforia Engine -> Model TargetA default Model Target database comprised of the NASA Viking Lander with two Guide Views (front and back) can then be added.

TIP: You can verify that a database was added from the overview in the Vuforia Configuration (Cmd+Shift+V/Ctrl+Shift+V).

  1. When a Model Target is added in the scene, a preview model representing the Model Target will be shown. The purpose of this model is to aid you in placing an augmentation relative to specific parts of the physical object itself - it is only visible in the Scene view of the Unity Editor and it will not appear at runtime.
  2. In the Inspector window of the Model Target, verify that the Physical LengthPhysical Width and Physical Height fields match the dimensions of your real-world object, in meters. Size differences between the physical object and the Model Target is known to affect tracking quality.
  3. Add a cube or other content as a child to the Model Target GameObject.
  4. Test your model target with Vuforia's Play Mode in Unity by pressing the Play button in Unity. Or, deploy the app to your device.

Configuration for a Model Target with one or more Guide Views

A Model Target can be generated with one or more Guide Views for starting tracking of an object from different angles. See Guide Views for details. Select which Guide View to show in the Model Target Behaviour component of the Model Target GameObject, Guide Views must be set up in the MTG beforehand

Advanced Model Targets don’t require a Guide View. See Configuration for Advanced Model Target Databases in the section below for more information.

  1. Choose between Front and Back Guide Views from the dropdown menu when using the Model Target Sample.

Guide View display mode

The Guide View Mode lets you select how the Guide View should be rendered. NoGuideView will not render the Guide View on the screen. Use this mode for adding your own application logic to present target detection.

GuideView2D renders the pre-configured Guide View.

GuideView3D should be used with HoloLens or Magic Leap and lets you use a 3D model to represent object and detection position.

  1. At runtime, and with the GudieView2D mode enabled, an outlined representation of the object is rendered on the screen- this is the Guide View.
  2. When matched with the object, the Guide View image will disappear, which indicates that tracking has started.

  1. To customize your AR experience, place custom content as child objects of the ModelTarget Game Object. Align your content relative to the preview model.

NOTE: If you are using the NASA Viking Lander model you can import content for the model through the Vuforia Core Samples package.

Manually switching between Guide Views

If your Model Target has multiple Guide Views, you can switch between them in a custom C# script with SetActiveGuideViewIndex():

// The index to activate must between 0 and mModelTarget.GetNumGuideViews()-1
var guideViewIndexToActivate = 0;
mModelTarget.SetActiveGuideViewIndex(guideViewIndexToActivate);
// Or, set Guide View to activate by string name
string guideViewNameToActivate = "Front";
mModelTarget.SetActiveGuideViewName(guideViewNameToActivate);

 Configure the Model Target

Model Target tracking can be optimized to your use case with a motion hint and tracking mode. The Model Target’s parameters can be set already in the Motion Hint and Model Type menus in the Model Target Generator. However, the value can be manually overridden in Unity. Please see the articles Optimizing Model Target Tracking for details on the tracking mode and motion hint.

Configuration for Advanced Model Target Databases

Configuring for Advanced Model Target databases use the same GameObject ModelTarget. An Advanced Model Target database is trained through the Model Target Generator. For more information refer to this article: Model Target Generator User Guide and Advanced Model Target Databases.
The setup of Advanced Model Targets is similar to the steps above, with exception of the Guide views

  1. Go to GameObject -> Vuforia Engine -> Model Targets -> Model Target to create a ModelTarget GameObject in your scene. Select the newly created GameObject in the scene hierarchy window.
  2. In the Inspector window, select the Database dropdown menu and select your imported Advanced Model Target database.

  1. If you are using multiple Models in one database, then you may choose between the Model Targets stored in the database in the Model Target. Switch between the models as you add content to the models. Keep in mind that all content must be child objects of the ModelTarget GameObject.

NOTE: Unlike standard Model Targets, Advanced Model Targets will automatically be detected without first displaying a Guide View on the screen.

It is therefore good practice to display some general guidance to the user to identify the object that can be tracked. The following code shows how this could be done (see more best practice recommendation on the Model Target Guide View page):

if (mModelTargetBehaviour.TargetStatus.StatusInfo == StatusInfo.INITIALIZING)
{
   // All model targets in the scene are initializing, display custom UI here
}
  1. Configure the ModelTarget GameObjects and add content to them as you would with other Model Targets.

Advanced Occlusion

By adding advanced occlusion functionality to your Model Targets you can further immerse your end users or partmentalize the object's features. See How to Use the Occlusion Model in Unity to learn more.

Learn More

Model Targets Overview

Model Targets API Overview

Model Target Generator User Guide

Model Target Test App User Guide