- Home /
Why my object is ''destroyed'' when it's actually still in the scene?
Many questions on this topic... and yet I don't find the solutions to be relevant for me... I have a PlayableDirector in my AR scene, each time the target image is found the playable director is playing. When the image target is lost the playable director is paused and so on. Why do I get this error?
MissingReferenceException: The object of type 'PlayableDirector' 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.
Why and When the palyable director is suddenly CONSIDERED to be destroyed?!
After adding the null check the error still persists.
this is my code (added some line to vuforia DefaultTrackableEventHandler public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus) { if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED || newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) { Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); StartCoroutine(TrackingFoundRoutine()); OnTrackingFound(); } else if (previousStatus == TrackableBehaviour.Status.TRACKED && newStatus == TrackableBehaviour.Status.NO_POSE) { Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost"); print("B"); frames.gameObject.SetActive(true); if (playable != null) { playable.Play(); } playable.Pause(); OnTrackingLost(); } else { print("C"); frames.gameObject.SetActive(true); if (playable != null) { playable.Play(); } playable.Pause(); OnTrackingLost(); } } private IEnumerator TrackingFoundRoutine() { frames.transform.SetParent(gameObject.transform, false); frames.GetComponentInChildren<Animator>().SetTrigger("IconGlow"); yield return new WaitForSeconds(5f); frames.gameObject.SetActive(false); if (playable != null) { playable.Play(); } }
Can't make the citation look properly so use this red font citation
public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRAC$$anonymous$$ED || newStatus == TrackableBehaviour.Status.EXTENDED_TRAC$$anonymous$$ED)
{
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
StartCoroutine(TrackingFoundRoutine());
OnTrackingFound();
}
else if (previousStatus == TrackableBehaviour.Status.TRAC$$anonymous$$ED && newStatus == TrackableBehaviour.Status.NO_POSE)
{
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
print("B");
frames.gameObject.SetActive(true);
if (playable != null)
{
playable.Play();
}
playable.Pause();
OnTrackingLost();
}
else
{
print("C");
frames.gameObject.SetActive(true);
if (playable != null) {
playable.Play(); }
playable.Pause();
OnTrackingLost();
}
}
private IEnumerator TrackingFoundRoutine()
{
frames.transform.SetParent(gameObject.transform, false);
frames.GetComponentInChildren<Animator>().SetTrigger("IconGlow");
yield return new WaitForSeconds(5f);
frames.gameObject.SetActive(false);
if (playable != null)
{
playable.Play();
}
}
}
I feel like I don't have enough information about the script to fix the issue. But maybe that's just me. If "frames.gameobject" = PlayableDirector, then the gameobject is SetActive(false) almost at the bottom. $$anonymous$$aybe this causes an issue.
Hi @metalted thanks for posting the script above. The "frames.gameobject" does not equal PlayableDiroector. "playable" is the PlayableDirector.