Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Anchoring a prefab spawned by tracked image

Discussion in 'AR' started by japosm1, Sep 29, 2021.

  1. japosm1

    japosm1

    Joined:
    Sep 29, 2021
    Posts:
    1
    Is it possible to spawn a prefab once the camera detects a reference image and then immediately anchor this and not allow it to move when the reference image is no longer in view? I'm attempting to spawn a very large prefab when a user scans a QR code located on the floor and then have them be able to look up and walk around the prefab without it moving once the QR code is no longer visible.
     
  2. SpaceToastDotNet

    SpaceToastDotNet

    Joined:
    Sep 14, 2020
    Posts:
    9
    I'd done this by setting the position and orientation of the spawned prefab manually when it's generated, rather than parenting it to the image:

    Code (CSharp):
    1.   void OnChanged(ARTrackedImagesChangedEventArgs eventArgs){
    2.     foreach (var trackedImage in eventArgs.added){
    3.       if (trackedImage.referenceImage.name=="trigger_mushroom"){
    4.         GameObject shroom = Instantiate(mushroomPrefab, trackedImage.transform.position, trackedImage.transform.rotation);
    5.       }
    6.     }