Search Unity

Question Match Action: OnMatchAquire -> tell MARS to stop scanning

Discussion in 'Unity MARS' started by macgregger, Jul 4, 2022.

  1. macgregger

    macgregger

    Joined:
    Feb 13, 2018
    Posts:
    28
    Hello everybody,

    I'm making a marker-based game and I'm running into some issues. Unity MARS recognizes the image on my wall without problem and places the content correctly.
    My game requires the user to alternate between mikro and makro-view (to get close with the phone and then to back up again). During this transition Unity MARS makes a lot of new match aquires, which are not really needed, since the game was placed correctly at the start.
    I'd like to use the OnMatchAquire on my Marker-Proxy and add a new event that tells MARS to stop searching for the marker once it has been successfully found.

    Is there already a script for something like that. And if not does anybody know how to write something like this?

    Thank you for your help.
     
  2. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Hi there! Sorry to hear you're having trouble.

    There are a few ways to stop MARS from doing stuff. The "nuclear option" is `MARSCore.Paused`, which is a static bool field which can be used to temporarily suspend all MARS systems from running. Data providers won't update, and the solver won't solve. Another way is to just get things to slow down by increasing the interval between solves in `Project Settings > MARS > Runtime > Evaluation Interval`. Using something like 1 second might be a better interval for your particular experience. Or you could switch `Startup Mode` in that same settings menu to `Wait for Request`, and use a script to explicitly control when the solver should run.

    However, it sounds like what you're asking for is to just disable image marker tracking when your proxy is acquired. I would do this by adding a MatchAction to the proxy which calls a method on some script. Have this script subscribe to `IUsesMarkerTracking` and then call `this.StopTrackingMarkers();` in that method. This will stop the marker tracking data provider from tracking, so bear in mind that updates to that image (like if it moves) will be missed.

    Another approach would be to split the Proxy apart from its content, so that the content can persist even after the match is lost and "reattach" when it is found. The `ShowChildrenOnTrackingAction` just isn't built for that kind of situation, as it tries to accurately reflect the tracking data we are getting from the device. To do this, I would recommend that you create a separate object (which is not a child of the proxy) for the content which starts inactive, but exposes public method to activate and update its position, which can be driven by `MatchAction` events. Basically just ignore the "match loss" event, and your content will stay where it is between matches.

    For an example of what I'm talking about with option 2:
    Code (CSharp):
    1. using Unity.MARS.Providers;
    2. using Unity.XRTools.ModuleLoader;
    3. using UnityEngine;
    4.  
    5. public class DisableImageTrackingOnMatch : MonoBehaviour, IUsesMarkerTracking
    6. {
    7.     IProvidesMarkerTracking IFunctionalitySubscriber<IProvidesMarkerTracking>.provider { get; set; }
    8.  
    9.     public void StopMarkerTracking()
    10.     {
    11.         this.StopTrackingMarkers();
    12.     }
    13.  
    14.     public void StartMarkerTracking()
    15.     {
    16.         this.StartTrackingMarkers();
    17.     }
    18. }
    19.  
     
  3. macgregger

    macgregger

    Joined:
    Feb 13, 2018
    Posts:
    28
    Thank you @mtschoen for the very detailed answer. I'll try it right away.
     
    mtschoen likes this.
  4. seyyedebrahimi

    seyyedebrahimi

    Joined:
    Jan 17, 2022
    Posts:
    1
    Hey all
    I have a target tracking in unity MARS. It works perfectly when it found my target, but I need to destroy that object, if there the marker is not tracking (is not seen by camera). What should I do? I tried using Match Action > On Match Acquire to enable game object and then Match Action > On Match Loss to disable it. The enabling action works fine, but the loss action is not working.