Log in or register to post comments

Dynamically/Programatically Adding New ImageTargets

June 23, 2016 - 4:40am #1

We are using many ImageTarget prefabs in conjunction with Video playback augmentations and a device database for targets.

The problem is that if we need to add a new image target to the library, we have to add it to the project and rebuild and re-release the app.  

Ideally, we want the app be able to detect a new targetDB XML file on our server, download the XML and DAT files, read those and loop through the image targets instantiating ImageTarget instance for each.

Whilst we can obtain new XML/DAT files, each ImageTarget needs to be set up in advance in Unity and assigned to a named tracker from the targetDB.  So if we do add a new target, there is no ImageTarget instance to utilise it.

I have been able to successfully Instantiate the ImageTarget prefab but the problem arises when setting the properties.  It seems to be that Vuforia explicitly stops us from doing this as the components' properties that need setting are all read-only at runtime.

Is there any way around this?  It is far from ideal having to essentially hard code the ImageTarget objects, especially when I believe this is completely doable in Native Objective C or Java.

Naturally I want our app to be dynamic whilst allowing us to separate the code from the content as much as possible.

Thank you in advance.

Dynamically/Programatically Adding New ImageTargets

June 23, 2016 - 8:49am #2

timgoon wrote:

...Whilst we can obtain new XML/DAT files, each ImageTarget needs to be set up in advance in Unity and assigned to a named tracker from the targetDB....

 

You don't have to setup every Image Targets "in advance" in the Unity scene, and in fact you don't even have to use the Image Targets prefab.

That's just a convenience way of setting up an ImageTarget, but you can also work in a more "programmatic" way, by writing script code that loads your Dataset and by querying the StateManager of Vuforia at every frame so to know what are the currently tracked targets in the camera view;

based on that, you can then dynamically (programmatically) attach an augmentation (e.g. a 3D model or anything you like) to the Image Target. So, no need to instantiate the ImageTarget Prefabs and trying to edit their properties.

 

This article explains how this can be achieved:

https://developer.vuforia.com/forum/faq/unity-how-do-i-get-list-active-trackables

 

Log in or register to post comments