AR Vuforia locking objects problem

Hey all,

I need your help. I’m currently creating an AR app with Unity and Vuforia. I’m close to the finish only one part is missing and that is where I need your help.
The app is working with an image tracker and extended tracking. When the camera discovers the tracker the object appears and a button also appears. When I hit the button the object explodes and you can see what’s inside of it. Then after the explosion another button appears where the objects that jumped out of the object return to the originally position.
The explosion and returning of objects are happening in a smooth movement. If the camera looses the target and finds it again the object is going to be resetted. All of this is working fine.
The last thing I want to add is a lock button. So after the explosion a lock button appears and when I hit the lock button the object should not reset, even if it looses and then sees the tracker again. And that is where I can’t get further. I tried to solve it with a bool variable but for some reason it is not working and I don’t know why.

public class ShowUIScript : MonoBehaviour, ITrackableEventHandler
{
//Usually here is long part where all the scripts, objects and their positions are defined
    bool firstTracked = false;
    public bool resetDone = true;
    public bool locked=false;
    private TrackableBehaviour mTrackableBehaviour;

void Start()
{
 //Part where more positions and objects are defined
  if (mTrackableBehaviour)
  {
  mTrackableBehaviour.RegisterTrackableEventHandler(this);
  }
}

public void Locker() {
   if(!locked) { 
       locked = true;
       HideLockButton();
       ShowOpenButton();
    }  else {
      locked = false;
      HideOpenButton();
      ShowLockButton(); 
    }
}

public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
{   
if (!locked &&(newStatus == TrackableBehaviour.Status.DETECTED || 
newStatus == TrackableBehaviour.Status.TRACKED|| 
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) )                       
  {
     ShowExplodeButton();
     HideResetButton();
     SetToOriginal();
     firstTracked = true;
   } else {
      movementScript.StopMovement();
      resetScript.StopReset();  
      HideExplodeButton();
      HideResetButton();
    if (!firstTracked && !resetDone && !locked) 
     {
       SetToOriginal();
       resetDone = true;
       firstTracked = false;
      }
      else if (!firstTracked && !resetDone && locked)
      {
      //don't even know what to write here because my brain is totally fucked up
      }             
   }
 }
}

resetDone changes to false when the object explodes.

I hope you understand what I mean. The problem here it gets never to line 51. When I hit the lock button (after the explosion) the bool of locked changes to true but then it jumps to the Vurofia.DefaultInitializationErrorHandler script and goes back to my script and the looked is false again.

What can I do?

Hello I-Bims,
What code is running in the DefaultInitializationErrorHandler script when it jumps over to it?
I just did a quick test with the sample project where I had a button set a bool to true on the DefaultTrackableEventHandler script. This bool remained set to true while detecting and losing the image target it was associated with. Do you have any other code setting locked to false?
Thanks,
Vuforia Support

Hi,
this code is running:

namespace Vuforia
{
    /// <summary>
    /// A custom handler that registers for Vuforia initialization errors
    /// </summary>
    public class DefaultInitializationErrorHandler : MonoBehaviour
    {
        #region PRIVATE_MEMBER_VARIABLES

        private string mErrorText = "";
        private bool mErrorOccurred = false;

        private const string WINDOW_TITLE = "Vuforia Initialization Error";

        #endregion // PRIVATE_MEMBER_VARIABLES

        #region UNTIY_MONOBEHAVIOUR_METHODS

     void Awake()
     {
            // Check for an initialization error on start.
VuforiaRuntime.Instance.RegisterVuforiaInitErrorCallback(OnVuforiaInitializationError);
     }

        void OnGUI()
        {
            // On error, create a full screen window.
            if (mErrorOccurred)
                GUI.Window(0, new Rect(0, 0, Screen.width, Screen.height),
                                       DrawWindowContent, WINDOW_TITLE);
        }

        /// <summary>
        /// When this game object is destroyed, it unregisters itself as event handler
        /// </summary>
        void OnDestroy()
        {
            VuforiaRuntime.Instance.UnregisterVuforiaInitErrorCallback(OnVuforiaInitializationError);
        }

        #endregion // UNTIY_MONOBEHAVIOUR_METHODS

        #region PRIVATE_METHODS

   public void OnVuforiaInitializationError(VuforiaUnity.InitError initError)
   {
       if (initError != VuforiaUnity.InitError.INIT_SUCCESS)
       {
         SetErrorCode(initError);
         SetErrorOccurred(true);
       }
   }
        #endregion // Vuforia_lifecycle_events
  }
}

It jumps to line 25 to void OnGUI()

No only in Locker() locked can be set to false.
I think I solved the problem by setting locked in line 6 to static:

 public static bool locked=false;