Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering custom input kinds seems impossible #651

Open
Cedev opened this issue Oct 17, 2024 · 1 comment
Open

Registering custom input kinds seems impossible #651

Cedev opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@Cedev
Copy link

Cedev commented Oct 17, 2024

Which feature is frustrating to use or confusing?

Registering custom input kinds with CentralInputStore seem impossible. It's documented to do so

/// This plugin is added by default by [`InputManagerPlugin`],
/// and will register all of the standard [`UserInput`]s.
///
/// To add more inputs, call [`CentralInputStore::register_input_kind`] during [`App`] setup.

pub struct CentralInputStorePlugin;

During App setup the CentralInputStore, once it's been created, will be inside a resource inside the world inside the app, but register_input_kind require a mutable reference to the app in order to add a system.

pub fn register_input_kind<I: UpdatableInput>(
&mut self,
kind: InputControlKind,
app: &mut App,

This is impossible because you need to hold a mutable reference to the App and to the CentralInputStore which is inside of it at the same time, exactly a situation the rust borrow checker is designed to prevent.

Expectation

How do you intuitively expect this to behave?

Instead provide a method that takes the App, the control kind, and the UpdatableInput type, finds the CentralInputStore from the App, mutates its state as necessary and then adds the system to the App (while no longer holding a mutable reference to the CentralInputStore at the same time).

@Cedev Cedev added the usability Reduce user friction label Oct 17, 2024
@alice-i-cecile alice-i-cecile added bug Something isn't working and removed usability Reduce user friction labels Oct 17, 2024
@alice-i-cecile
Copy link
Contributor

This should be changed to only take a mutable reference to the app, and then fetch the CentralInputStore from the App.

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants