Remove PhysicalPressEventRouter
We have gotten feedback that Interactable + InteractablePressEventRouter + Pressable Button is confusing for developers.
Specifically, they don't understand how the components work together, and often don't know they need to add components such as PhysicalPressEventRouter.
One way to simplify this is to remove one of the components: PhysicalPressEventRouter.
The PhysicalPressEventRouter is just a component that looks for an Interactable object and calls "OnClick" on the interactable.
Instead, we propose the following changes to
Add a "Forward clicks to interactable" checkbox to PressableButton Add the dropdown to specify when to forward clicks to PressableButton Remove PressableButtonEventRouter. Note, that instead of actually looking for the router and calling OnClick directly, we can just raise the PointerClicked event from the button. Not sure yet what implementation is better.
Comment from Jonathan Palmer:
I agree this is a architecture conveyance problem and removing the overloading that the EventRouter causes.
I do not think removing it in entirety is the best step. If we do, we'd lose that level of abstraction of a dev wanting to have PressableButton sending events to non-Interactables, or if a dev wants to have it process in a different way then On Touch/Click/Press. Those were the main reasons for the EventRouter's original creation.
I think we want to fold the EventRouter into PressableButton's behavior as a private variable handler rather than a component on the gameobject. It continuing to be a component is a needless gotcha moment. Devs could select a router through a custom inspector dropdown, defaulting to something like our current one.
This solves the overloading problem while maintaining the layer of abstraction which makes PressableButton more flexible.
This reduces inspector overload, especially if the UnityEvents could become foldouts and populated with the default routing cases at runtime.
Ported from internal database.
@killerantz do you have any thoughts/concerns on the proposal above? Do you think we need more information?
I like the PhysicalPressEventRouter because it shows a good pattern of setting state and pushing events through Interactable. I also agree that it is another component to add when there are others that sound like that functionality would already exist, like the PressableButton or the NearInteractionTouchable.
I want to consider the different paths one might build a button. we could start with PressableButton, add the NearInteractionTouchable (should this be required with pressableButton), then add Interactable to handle feedback for far interaction. It seems like a lot already. We could add the router functionality to PressableButton or NearInteractionTouchable, depending on which one is more UI feedback focused. My vote it pressableButton.
The other route is having a button that already works for far interaction or in MR, then we want to add PressableButton functionality. Again, adding the pressableButton (should also add NearInteractionTouchable), setup the visual feedback for press and everything else should continue to work.
I actually started moving some of that functionality to Interactable with PR #4357 , but that means some of the functionality is duplicated with pressableButton. The easiest thing would be to create a public method for click on Interactable and you can call it from the event of your choice on PressableButton. There are a couple public methods already, SendOnClick(IMixedRealityPointer) or OnPointerClicked(MixedRealityPointerEventData), but they both have parameters not supported by the UnityEvent parameter field.
Super old at this point, but wanted to tag some people as we're looking at what buttons look like in v3: @CDiaz-MS @Zee2 @RogPodge
Might be some interesting context in here for why things are the way they are and ideas for how we might improve. Might be something of relevance; might not!
A good direction would be taking all the View functionality, like themes and feedback, out of Interactable. Have a base button class that is only events, then we can add states, themes, pressable button triggers and other visuals on top. Drive button states based on the types of handlers the button processes, like grab, physical press, focus.
The state system (which drives themes) is a stub of what it could have been, the idea was to have something that's super configurable. If it's separate from the button, then we can route the events into the theme system to set any number of states, even non-button related states like collision, data updates. In the current setup the states drive the button events, maybe it should be the other way around to allow more flexibility.
The pressable button is a good template for setting up complex interactions. It just seems weird to have the PhysicalPressEventRouter when it seems like you should be able to link events from Pressable button directly into Interactable.
My wish list:
- What types of events do we consume? This could be done with the current pattern of adding components like NearInteractionTouchable or using check boxes - though the later would require code updates if a new type of interaction is added.
- Are they pointer only events?
- Speech commands can break Interactable if they are set to global and pointer events are expected to be local. (maybe worth removing from the button and use the voice command components.) - Though I would like to get events or state changes to show feedback like it was pressed by the speech command.
- Global events are nice for designers to setup a click anywhere button. Maybe that's a different thing?
-
We can add tools/components to configure rules for interactions - like PressibleButton. Even a simple button has rules, like focus is required for press, some buttons have a time limit to trigger a click and allow a drag off to cancel.
-
The base button has states based on the handled events and rules. We can use these to drive feedback
-
Designers and engineers can wire up button events. OnFocus, OnClick, OnToggle (*more on toggles below)
-
A Theme system to provide feedback through animation, sound and visual changes.
Interactable tried to put all that into a single inspector component, maybe that was too ambitious, plus it also broke the pattern of adding components to change functionality. I was trying to balance designer vs. engineering needs and figured one complex component would be less of a learning curve than many simpler components even if we might have sacrificed some flexibility. After lessons learned, I would err on the side of consistent patterns and flexibility.
What is a button in MR? It could be a flat UI button on a slate that should react to near and far interactions or it could be a space capsule in orbit. I can grab it to inspect it, let it go or even throw it. It would be nice to add a throw state and throw event without having to write a new button system.
*A toggle could have more than two dimensions, though be mostly use selected and unselected. A speed control toggle could have 1x, 2x, or 4x as dimensions.
My favorite parts of Interactable are the themes, there are some good button rules (toggles) and the event/receiver system. Though for the event/receivers I would stick with the receiverBaseMonoBehaviour instead of the others ReceiverBase classes that can be detected by the Receiver system. It's nice to have an easy way to attach a new event type to the Interactable.
We have ended up with a pattern very similar to what @killerantz discussed in the previous comment, enabled through XRI in MRTK3.
- Data/model-only component:
PressableButton(or, the base classStatefulInteractablefor non-buttony-things) - View/visualization:
StateVisualizer
All inputs (physical touch, ray, etc) all route through the same "interaction model" component (interactable), and all visuals are displayed/rendered by StateVisualizer.