Expand description

A simple but robust input-action manager for Bevy: intended to be useful both as a plugin and a helpful library.

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 your 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.

This library seamlessly supports both single-player and local multiplayer games! Simply add the InputManagerBundle to each controllable entity, and customize the InputMap appropriately.

Of particular note: this plugin allows users to configure which state (i.e. GameState::Playing) it runs in. No more characters wandering around while your menu is open!

Features

  • Full keyboard, mouse and joystick support for button-like inputs.
  • Effortlessly wire UI buttons to game state with one simple component!
    • When clicked, your button will send a virtual button press to the corresponding entity.
  • Store all your input mappings in a single InputMap component
    • No more bespoke Keybindings<KeyCode>, Keybindings<Gamepad> headaches
  • Look up your current input state in a single ActionState component
    • Easily check player statistics while reading input
    • That pesky maximum of 16 system parameters got you down? Say goodbye to that input handling mega-system
  • Ergonomic insertion API that seamlessly blends multiple input types for you
    • input_map.insert(Action::Jump, KeyCode::Space) XOR input_map.insert(Action::Jump, C)? Why not both?
  • Full support for arbitrary button combinations: chord your heart out.
    • input_map.insert_chord(Action::Console, [KeyCode::LCtrl, KeyCode::Shift, KeyCode::C])
  • Create an arbitrary number of strongly typed disjoint action sets: decouple your camera and player state.
  • Local multiplayer support: freely bind keys to distinct entities, rather than worrying about singular global state
  • Leafwing Studio’s trademark #![forbid(missing_docs)]

Limitations

  • The Button enum only includes KeyCode, MouseButton and GamepadButtonType.
    • This is due to object-safety limitations on the types stored in bevy::input::Input
    • Please file an issue if you would like something more exotic!
  • No built-in support for non-button input types (e.g. gestures or analog sticks).
    • All methods on ActionState are pub: it’s designed to be hooked into and extended.
  • Gamepads must be associated with each player by the app using this plugin: read from the Gamepads resource and use InputMap::set_gamepad.

Modules

This module contains ActionState and its supporting methods and impls.

This module contains InputMap and its supporting methods and impls.

Everything you need to get started

The systems that power each InputManagerPlugin.

Helpful abstractions over user input

Structs

This [Bundle] allows entities to collect and interpret inputs from across input sources

A [Plugin] that collects [Input] from disparate sources, producing an ActionState to consume in game logic

Enums

[SystemLabel]s for the crate::systems used by this crate

Traits

A type that can be used to represent input-agnostic action representation

This trait designates that an Enum can be iterated over. It can be auto generated using strum_macros on your behalf.

Derive Macros