A straightforward but robust input-action manager for Bevy.
Inputs from various input sources (keyboard, mouse and gamepad) are collected into a common ActionState
on your player entity,
which can be conveniently used in your game logic.
The mapping between inputs and actions is many-to-many, and easily configured and extended with the InputMap
components on each player entity.
A single action can be triggered by multiple inputs (or set directly by UI elements or gameplay logic),
and a single input can result in multiple actions being triggered, which can be handled contextually.
InputMap
component
Keybindings<KeyCode>
, Keybindings<Gamepad>
headachesActionState
component
input_map.insert(Action::Jump, KeyCode::Space)
and input_map.insert(Action::Jump, GamepadButtonType::South)
? Have both!input_map.insert_chord(Action::Console, [KeyCode::ControlLeft, KeyCode::Shift, KeyCode::C])
ClashStrategy
enum: stop triggering individual buttons when you meant to press a chord!ActionDiff
representation to send on the wireapp.send_input(KeyCode::B)
or world.send_input(UserInput::chord([KeyCode::B, KeyCode::E, KeyCode::V, KeyCode::Y])
#![forbid(missing_docs)]
Gamepads
resource and use InputMap::set_gamepad
.Development occurs on the dev
branch, which is merged into main
on each release.
This ensures the examples are in-sync with the latest release.
leafwing-input-manager
to your Cargo.toml
.Actionlike
trait for it.InputManagerPlugin
to your App
.InputManagerBundle
to your player entity (or entities!).InputMap
component on your player entity.ActionState
component on your player entity to check the collected input state!```rust, ignore use bevy::prelude::; use leafwing_input_manager::prelude::;
fn main() {
App::new()
.addplugins(DefaultPlugins)
// This plugin maps inputs to an input-type agnostic action-state
// We need to provide it with an enum which stores the possible actions a player could take
.addplugins(InputManagerPlugin::
// This is the list of "things in the game I want to be able to do based on input"
enum Action { Run, Jump, }
struct Player;
fn spawnplayer(mut commands: Commands) {
commands
.spawn(InputManagerBundle::
// Query for the ActionState
component in your game logic systems!
fn jump(query: Query<&ActionState
This snippet is the minimal.rs
example from the examples
folder: check there for more in-depth learning materials!