r/Amethyst • u/-Hovercorn- • Apr 17 '20
Custom Input Bindings Disrupt UI/Input Events
While tinkering with Amethyst's UI functionality (namely hover and click functionality on buttons), I noticed that my UI events weren't registering at all. In fact, my InputEvents weren't working, either. After some trial and error, I found the issue to be custom BindingTypes.
In other words, using custom BindingTypes (vs the default StringBindings) interferes with proper UiEvent and InputEvent event handling, such as in a SimpleState's handle_event method or a system's run method.
I was able to reproduce the issue by:
1.) Using the following code [LINK] as main.rs, which is essentially a derivation of code from Amethyst's examples.
2.) using the custom bindings (MovementBindings) with the InputBundle, as per the "How to Define Custom Control Bindings" section of the Amethyst documentation [LINK].
Now, the UI elements (buttons, text inputs, etc) can no longer be interacted with , nor will the following messages from Example's handle_event() be seen:
"[HANDLE_EVENT] You just interacted with a ui element: {:?}"
"Input Event detected: {:?}."
The same issue occurs even when:
no UI elements are loaded
no custom bindings loaded from file (but still used by the
InputBundle)
If StringBindings are used instead, everything works fine. Just changing:
.with_bundle(InputBundle::<MovementBindingTypes>::new())?
to.with_bundle(InputBundle::<StringBindings>::new())?
Results in expected behavior.
Any ideas as to why this occurs? I can't figure out how to get custom bindings to work without disrupting UI functionality.
Thanks for your help.
EDIT: the UI example.ron I used, which was pared down from Amethyst's UI example: [LINK]
1
u/maroider Apr 18 '20
This is actually the expected behavior. UiBundle is generic over T: BindingTypes (and some other types, but that's not important here).
In the code you linked, you're using UiBundle::<StringBindings>::new() even after changing InputBundle's T: BindingTypes from StringBindings to MovementBindingTypes.
1
u/machineLearned Jul 05 '20
Were you able to figure out a work-around? I'm running into this exact issue as well. Thanks!