Log in or register to post comments

Tracker Lost/Found - User Feedback HLEP!!! NEEDED!!!

August 31, 2012 - 1:21pm #1

I am trying to do something really really simple here. It's just that I have been at it for so long now. It makes no sense. 

1. All I am trying to do is display a GUITexture object on screen when the tracker is lost and remove the same GUITexture object when tracker found. It work's except I get this error: 

[ MissingReferenceException: The object of type 'GUITexture' has been destroyed but you are still trying to access it.

Your script should either check if it is null or you should not destroy the object. ]

 

Here's the code i moddified: //DefaultTrackableEventHandler.cs

/*==============================================================================

            Copyright (c) 2012 QUALCOMM Austria Research Center GmbH.

            All Rights Reserved.

            Qualcomm Confidential and Proprietary

==============================================================================*/

 

using UnityEngine;

 

// A custom handler that implements the ITrackableEventHandler interface.

public class DefaultTrackableEventHandler : MonoBehaviour,

                                            ITrackableEventHandler

{

    #region PRIVATE_MEMBER_VARIABLES

 

    private TrackableBehaviour mTrackableBehaviour;

    

    #endregion // PRIVATE_MEMBER_VARIABLES

 

 

 

    #region UNTIY_MONOBEHAVIOUR_METHODS

 

//public ar_warning cacheWarning;

public GUITexture arWarning;

Color colorFrom; // Alpha 100

Color colorTo; // Alpha zero

    

    void Start()

    {

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

        {

            mTrackableBehaviour.RegisterTrackableEventHandler(this);

        }

 

DontDestroyOnLoad(arWarning);

        OnTrackingLost();

 

    }

 

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

 

 

 

    #region PUBLIC_METHODS

 

    // Implementation of the ITrackableEventHandler function called when the

    // tracking state changes.

    public void OnTrackableStateChanged(

                                    TrackableBehaviour.Status previousStatus,

                                    TrackableBehaviour.Status newStatus)

 

    {

        if (newStatus == TrackableBehaviour.Status.DETECTED ||

            newStatus == TrackableBehaviour.Status.TRACKED)

        {

            OnTrackingFound();

        }

        else

        {

 

            OnTrackingLost();

 

        }

    }

 

    #endregion // PUBLIC_METHODS

 

 

 

    #region PRIVATE_METHODS

 

 

    private void OnTrackingFound()

    {

 

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

 

        // Enable rendering:

        foreach (Renderer component in rendererComponents) {

            component.enabled = true;

 

        }

 

Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

//arWarning.enabled = false;

colorFrom = colorTo = arWarning.color;

colorTo.a = 0;

 

 

    }

 

 

    private void OnTrackingLost()

    {

       

Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

 

        // Disable rendering:

        foreach (Renderer component in rendererComponents) {

            component.enabled = false;

 

        }

  Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");

  //arWarning.enabled = true;

  DontDestroyOnLoad(arWarning);

  colorFrom = colorTo = arWarning.color;

  colorTo.a = 127;

    }

 

    #endregion // PRIVATE_METHODS

}

 

 

 

 

 

Thanks for any help!

 

Tracker Lost/Found - User Feedback HLEP!!! NEEDED!!!

September 5, 2012 - 8:00pm #3

Niklas is right. DontDestroyOnLoad is intended to persist objects across scene changes. Is that what you're intending? If so, try removing those subsequent calls in the OnTrackingLost/Found callbacks.

Also have you assigned a GUITexture for the arWarning field in the Inspector?

Tracker Lost/Found - User Feedback HLEP!!! NEEDED!!!

September 4, 2012 - 12:29am #2

pixelboi wrote:

I am trying to do something really really simple here. It's just that I have been at it for so long now. It makes no sense. 

1. All I am trying to do is display a GUITexture object on screen when the tracker is lost and remove the same GUITexture object when tracker found. It work's except I get this error: 

[ MissingReferenceException: The object of type 'GUITexture' has been destroyed but you are still trying to access it.

Your script should either check if it is null or you should not destroy the object. ]

 

Please give us a line number.

It is even possible to double click the error message in the console; should take you to the offending line.

I dont see any references to destroyed objects in this code.

btw, you don´t need to repeatedly set the DontDestroyOnload(). It is probably not what you are after anyway ;)

 

 

Log in or register to post comments