-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Implement gamepads as entities #12770
base: main
Are you sure you want to change the base?
Conversation
@alice-i-cecile @mockersf I think this is mostly done, i will recheck the docs again once you decide if this should be merged or not. |
@cart, just to be sure: you're broadly in favor of representing gamepads as entities, correct? |
crates/bevy_gilrs/src/converter.rs
Outdated
pub fn convert_gamepad_id(gamepad_id: gilrs::GamepadId) -> Gamepad { | ||
Gamepad::new(gamepad_id.into()) | ||
// TODO: bevy_input directly depends on Gilrs::GamepadId's. This could cause conflicts with other plugins. | ||
// Instead, bevy_input should provide a unique GamepadId and bevy_gilrs keep a mapping between them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'm fine to leave this for follow-up though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like Entity should be that unique id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, i don't think this is a good idea right now until we can re-create entities with a given id.
Gilrs tries to reuse the same ids for reconnecting gamepads which allows us (and users) a way to preserve state. We could keep some mapping between dropped entities->current entity but that might be a bit of a foot-gun with users expecting their id(entity) to also persist.
EDIT: On second thought, on disconnection, we could leave the entity alive, remove the gamepad components and assume that if the user deleted the entity it no longer wants to preserve the state and create a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea in your edit. Eventually we could use entity disabling instead.
Provided we have a satisfying answer to my comment right above this, then yeah I'm broadly in favor. |
# Conflicts: # crates/bevy_input/src/gamepad.rs # crates/bevy_input/src/lib.rs
# Conflicts: # crates/bevy_input/src/button_input.rs # crates/bevy_input/src/gamepad.rs
Objective
Gamepads are a bit unergonomic to work with, they use resources but unlike other inputs, they are not limited to a single gamepad, to get around this it uses an identifier (Gamepad) to interact with anything causing all sorts of issues.
Solution
Using entities solves all the problems above and opens new possibilities.
Option<Rumble> or Option<Gyro>
), allows devs to attach their own components and filter them, so code like this becomes possible:Follow-up
Changelog
Added
TODO
Changed
TODO
Removed
TODO
Migration Guide
TODO