Search code examples
c#mrtk

MRTKv2 PressableRoundButton prefab with events with WMR HMD don't seem to be working for me


I've created a little test scene where I want to use the PressableRoundButton prefabs to additively load a scene when pressed. I've hooked up the button to call into a script and pass the name of the scene I want to load, this code is verified to work with a debug keyboard shortcut so I know that part is good. What doesn't seem to work is the button event itself. Perhaps I've gone and done something really stupid, but I stupidly can't figure out what I've done wrong.

I'm using the DefaultMixedRealityToolkitConfigurationProfile which may or may not be the problem but I'm a little unsure how to diagnose that. I kind of figured the default one would be the safest bet. I can see the button visually press down when I click on it using the WMR controller so all the mechanics behind the button are working in terms of having it push down and all when I hit the trigger while pointing at it

Button Events list


Solution

  • Thank you for sharing an image of your setup! Try calling your code not in the PressableButton component, but on the Interactable component's OnClick handler (you need to expand the "Events" dropdown in Interactable.

    The PressableButton component actually will only raise the button pressed, etc. events when you are directly poking a button with near interaction. For pressing the button at a distance, use the OnClick event handler in Interactable.

    Have a look at the picture here to see where the OnClick handler lives.

    Note that OnClick will only fire on pointer unpressed, and will also (currently) not fire if you stay pressed for too long. If you'd like to instead run the code when you press down, you can instead handle the OnPress event.

    Have a look here for that example.

    Note that by default Interactables only handle an OnClick event -- you add more event handlers by adding "Event Receivers" by clicking the "Add Event" button. You can then pick the receiver type. In the case of the round button prefab, there is already a InteractableOnPressReceiver set up for you that exposes the OnPress and OnRelease events.

    The way to think about buttons in MRTK is:

    • Interactable is actually a 'button' that can be interacted with both nearby and at a distance. It exposes many different event handlers, and has lots of visual options. It's called "Interactable" and not "Button" mostly for historical reasons (it was that way, people started using it, now changing it would break many people).
    • PressableButton is a more complex touch-only button that actually moves in with your finger. Pressable button actually talks to Interactable, setting things like its pressed state, so that folks can listen just to Interactable if they want to work both near and far.

    In most cases, add your event handlers to Interactable, not pressable button. Pressable button is for touch only.