Search Unity

AR Foundation - Multiple Tracked Image Managers?

Discussion in 'Handheld AR' started by drewfjacobs, Jun 19, 2019.

  1. drewfjacobs

    drewfjacobs

    Joined:
    Mar 12, 2019
    Posts:
    4
    I am trying to have different prefabs spawn for different images tracked. Would it it possible to just add a second AR Tracked Image Manager with a separate Reference Library and Tracked Image Prefab assigned to it in order to achieve this goal?
     
    ercuesy likes this.
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    518
    The AR managers are effectively singletons, so you should generally not use two of them. You can, however, set the active reference image library and the prefab at runtime.

    Another option to achieve this might be to use a prefab which just contains a single MonoBehaviour script that can decide which other prefab to instantiate as a child of itself.
     
  3. BMythes

    BMythes

    Joined:
    Feb 20, 2018
    Posts:
    6
    Sorry for reviving this thread, I'm just working on exactly the same thing you described here.

    A solution I was thinking was instantiating a Gameobject A that would be a parent of different prefabs B, C and D (all child prefabs start as inactive). And then, depending on which image is read from the library, it activates one of the prefabs.

    I also thought about having the library of images become an array, and associate that array with an array of prefabs. Hence, Image [0] would instantiate Prefab [0], etc.

    Are any of these solutions valid, and could you possibly point towards how to solve them? I'm still a beginner at code having a hard time with editing ARFoundation's code.

    Thank you!
     
    ercuesy likes this.
  4. ercuesy

    ercuesy

    Joined:
    Jul 6, 2019
    Posts:
    10
    Has anyone been able to figure this one out? I tried tdmowrer approach but ended up crashing the app. Is there an example of how to do it?
     
  5. jpvanmuijen

    jpvanmuijen

    Joined:
    Aug 23, 2012
    Posts:
    6
  6. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    518
    In ARFoundation 3.0, it is now possible to add an ARTrackedObjectManager and then set its reference object library. This wasn't possible before because it would throw if enabled without a reference object library. From the changelog:
    What is the callstack?
     
    ercuesy likes this.
  7. ercuesy

    ercuesy

    Joined:
    Jul 6, 2019
    Posts:
    10
    @tdmowrer I actually figured that an unused Wikitude library reference I was playing with was causing the crash, sorry for the confusion. I'll try the approach given by @jpvanmuijen and see how it goes, thanks!