Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Enable and disable a custom recognizer

FrimyFrimy
edited January 2017 in Questions And Answers

Hello,

I created a custom recognizer with a TappedEvent in the Start() function of my script:

void Start()
{
    recognizer = new GestureRecognizer();

    recognizer.TappedEvent += Recognizer_TappedEvent;

    recognizer.StartCapturingGestures();
}

private void Recognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
{
        //My code
}

My problem is that the function Recognizer_TappedEvent is called even when I did not break in my Start() function. I want it to be active when the script start and to be disabled when I disable the GameObject containing the script.

I though about using a boolean, but I guess there is a method much cleaner to do that.

Thank you in advance everyone!

Tagged:

Best Answer

  • S_LinckeS_Lincke
    Accepted Answer

    Just deregister your handler when the object gets disabled:

    void OnDisable() { recognizer.TappedEvent -= Recognizier_TappedEvent; }

    Just like that you can reenable it again in OnEnable if you need to.

Answers

  • S_LinckeS_Lincke
    Accepted Answer

    Just deregister your handler when the object gets disabled:

    void OnDisable() { recognizer.TappedEvent -= Recognizier_TappedEvent; }

    Just like that you can reenable it again in OnEnable if you need to.

  • It did the trick, thank you very much!

Sign In or Register to comment.