Deleting virtual buttons in vuforia unity ar.

Hi, I have a virtual button in my scene that I would like to destroy and I have the following script for it:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

public class Vbutton: MonoBehaviour, IVirtualButtonEventHandler

{

GameObject gb ;

void Start()

{

    GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);

   

}

void IVirtualButtonEventHandler.OnButtonPressed(VirtualButtonBehaviour Virtualbutton)

{

    if (this.transform.parent.gameObject)

    {

        Debug.Log("button Pressed");

        CancelInvoke("IVirtualButtonEventHandler");

        CancelInvoke(" IVirtualButtonEventHandler");

        Destroy(this.transform.parent.gameObject);

    }

}

void IVirtualButtonEventHandler.OnButtonReleased(VirtualButtonBehaviour Virtualbutton)

{

   

}

}

But i get the following HUMONGOUS error that I just do not get. Any suggestions?

Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> UnityEngine.MissingReferenceException: The object of type ‘VirtualButtonBehaviour’ 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.

at (wrapper managed-to-native) UnityEngine.Behaviour:get_enabled ()

at Vuforia.StateManager.UpdateVirtualButtons (Int32 numVirtualButtons, IntPtr virtualButtonPtr) [0x00000] in :0

at Vuforia.VuforiaManager.UpdateTrackers (FrameState frameState) [0x00000] in :0

at Vuforia.VuforiaManager.Update (ScreenOrientation counterRotation, System.Boolean& reapplyOldState) [0x00000] in :0

at Vuforia.VuforiaARController.UpdateStatePrivate (Boolean forceUpdate, Boolean reapplyOldState) [0x00000] in :0

at Vuforia.VuforiaARController.UpdateState (Boolean forceUpdate, Boolean reapplyOldState) [0x00000] in :0

at Vuforia.DigitalEyewearARController.Update () [0x00000] in :0

at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object,System.Exception&)

at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object parameters, System.Globalization.CultureInfo culture) [0x000d0] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222

— End of inner exception stack trace —

at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object parameters, System.Globalization.CultureInfo culture) [0x000eb] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232

at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object parameters) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115

at System.Delegate.DynamicInvokeImpl (System.Object args) [0x000b9] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:443

at System.MulticastDelegate.DynamicInvokeImpl (System.Object args) [0x00018] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/MulticastDelegate.cs:71

at System.Delegate.DynamicInvoke (System.Object args) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:415

at Vuforia.DelegateHelper.InvokeDelegate (System.Delegate action, System.Object args) [0x00000] in :0

UnityEngine.Debug:LogError(Object)

Vuforia.DelegateHelper:InvokeDelegate(Delegate, Object)

Vuforia.DelegateHelper:InvokeWithExceptionHandling(Action)

Vuforia.VuforiaBehaviour:Update()

Hi could you fix it? I am trying with the same, you press the button and the object do some transformation?