Start a new topic

Image Tracking: Loading multiple models

I am currently working on a project where I need to assign multiple models to different image targets . However, it seems that the AR Tracked Image Manager only allows for one model to be associated with each image target. Is there a way to support multiple models with multiple image targets in the same Unity scene? 

1 Comment

Hi, yes of course there is a way! 

The prefab that you can set within the ARTrackedImageManager is the one that gets instantiated with each image that's detected. In order to create a scenario where multiple images are instantiated with different prefabs you need to 

  1. Create a lookup table that maps the prefabs you want to instantiate to the name of the XRReferenceImage Struct XRReferenceImage | AR Subsystems | 4.0.12 (unity3d.com)
  2. Then register a callback to the ARTrackedImageManager.trackedImagesChanged event Event trackedImagesChanged | AR Foundation | 4.2.10 (unity3d.com)
  3. In that callback iterate over the added images. You can find the name of the image under ARTrackedImage.referenceImage.name  Class ARTrackedImage | AR Foundation | 4.0.12 (unity3d.com)
  4. Check the lookup table against the name of the detected image and instantiate the prefab as a child of the ARTrackedImage GameObject. 


Your lookup table could have several forms - I personally prefer creating a ScriptableObject Unity - Manual: ScriptableObject (unity3d.com) giving an easy user interface to fill in data, as well as a Dictionary<string, GameObject> (name, Prefab) - to access the lookup table via code.  

Login to post a comment