Start a new topic

Multible Image Targets with different Drawables at runtime

Hello,

I have seen that you can fetch a Target Collection on runtime in unity and create an Image Tracker. 

My question is because i cannot find anything on this for unity (even though i think for JavaScript there is an example).

Am i able to loop through the Image Targets (img1, img2, img3, ...) of the wtc file and attach different drawables to them?


So as a real world example:


I have a target collection with 5 images, i want those images to have different videos for each one. I will have a standard Video Prefab but the url for the video will change according to what image is being tracked.


Thank you in advance.


forgot to mention that this has to be done dynamically at run-time

Hi, 


There are two ways to accomplish this.


1. You can have a single ImageTrackable that is configured to recognize all the Image Targets in the collection. In this Image Trackable you add a callback method to the OnImageRecognized and OnImageLost events. When an Image Target is recognized your callback will be called with an ImageTarget, from which you can get the name of the image that was recognized. Based on the name, you can instantiate the appropriate prefab and place it as a child GameObject of the Trackable. When the Image Target is lost, the OnImageLost event will be triggered and here you should destroy the prefab created earlier.


2. You can have an ImageTrackable for each of the Image Targets. Each ImageTrackable is configured to recognize a single image from the collection. Additionally, you set a unique prefab in the Drawable field of the ImageTrackable. At runtime, when the image associated with this ImageTrackable is recognized, the prefab configured as a Drawable will be instantiated and set as a child GameObject to the ImageTrackable. When the image is lost, the instantiated prefab is automatically destroyed.


I would recommend the first method, since it is more flexible and scalable.


Best regards,

Alexandru


1 person likes this
Hello there I have a question in a similar vein to what Alexis asked above, so I wanted to follow up here first before starting a new topic.

I am currently using a setup similar to what you described in #2 of your response. I have a drawable prefab configured for each Trackable that is assigned to look for a single target image each. I am looking for a way to swap the drawable at runtime by way of an external event, in this case, touch input. Is it possible to swap out the drawable for another prefab at runtime? And if it is not possible, what approach would you recommend for me to get something close to what I am looking for, i.e. to swap between augmentations on a single tracked image target.

 

Hi, 


It is possible to swap the Drawable, but the change will only happen the next time you recognize the associated target. That is because the prefab is instantiated when the target is recognized, so even if you change the prefab, the instantiated version will still be visible until the target is lost.


Best regards,

Alexandru

Login or Signup to post a comment