Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Instantiating an ImageTarget prefab

Discussion in 'AR' started by rogerdv, Sep 16, 2023.

  1. rogerdv


    Jul 16, 2012
    I working on an apk that will manage around 100 image targets. I decided to create a prefab, load a list of images and instantiatte the prefab as many times as needed, then assign to each object the image and some label.
    But I havent worked in Unity since 2 years ago (and never worked with Vuforia) and I found some problems. First, I cant figure out how to pass a parameter to the OnTargetFound event. I add a parameter to the function, but in the editor (or via code), I see no way to configure the image target name in the event.
    Second, changing prefab Image and Target Name fields wasnt so easy to do from code. This is what I did:

    Code (CSharp):
    2. public GameObject TargetPref;   //ImageTarget object prefab
    3.     public ImageList Imgs;          //The list of image targets
    5. void Start()
    6.     {
    7.         if (Imgs.targets.Count > 0)
    8.         {
    9.             foreach (var t in Imgs.targets)
    10.             {
    11.                 GameObject it = Instantiate(TargetPref);
    12.        = t.tag;
    13.                 it.GetComponent<ImageTargetBehaviour>().TargetName = t.tag;
    14.                 it.GetComponent<ImageTargetBehaviour>().Image = t.img;
    16.             }
    17.         }
    19.     }
    But I get an error saying that TargetName is read only and another saying that ImageTargetBehaviour component has not a definition for Image (also tried image, unsuccessfully).
    How can I solve this? Is there some way to do it other than manually creating 100 ImageTarget objects?
  2. andyb-unity


    Unity Technologies

    Feb 10, 2022
    FYI Unity employees likely can't help with Vuforia questions.

    From our FAQ:

    rogerdv likes this.