Search Unity

Resolved OnImageChanged?

Discussion in 'AR' started by WILEz1975, Apr 14, 2022.

  1. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    375
    Hi, I'm no AR expert.
    I have a doubt.
    In nearly all examples, an event called OnImageChanged is used.
    When is this event called?
    At the change of an image, compared to what? The one previously framed and recognized?

    For eample:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.XR.ARFoundation;
    3.  
    4. public class ImageRecognition : MonoBehaviour
    5. {
    6.     private ARTrackedImageManager _arImageManager;
    7.  
    8.  
    9.     private void Awake()
    10.     {
    11.         _arImageManager = FindObjectOfType<ARTrackedImageManager>();
    12.     }
    13.  
    14.     public void OnEnable()
    15.     {
    16.         _arImageManager.trackedImagesChanged += OnImageChanged;
    17.     }
    18.  
    19.     public void OnDisable()
    20.         {
    21.  
    22.         _arImageManager.trackedImagesChanged -= OnImageChanged;
    23.     }
    24.  
    25.     public void OnImageChanged(ARTrackedImagesChangedEventArgs args)
    26.     {
    27.         foreach(var trackedImage in args.added)
    28.         {
    29.             //....my operations
    30.  
    31.  
    32.             }
    33.  
    34.         }
    35.  
    36.  
    37. }
    38.  
    When "...my operations" is runned?

    I ask this because the OnImageChanged event is only run the first time. If I frame the same image a second time, it is not detected.

    I need my operations to be performed every time that image is framed. I also tried cleaning the args.added list but it still doesn't work.
     
    Last edited: Apr 14, 2022
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    WILEz1975 likes this.
  3. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    375
    Thank you, args.updated was just what I was looking for. :)