cloudiful-bevy-camera
Reusable Bevy camera switching core.
What it provides
CameraSwitchPlugin: registers request handling and switch eventsSwitchableCamera: marker/config component for cameras managed by coreSwitchCameraRequest: external switch request APICameraSwitched: emitted when active switchable camera changes
What it does not provide
- camera spawning or setup helpers
- keyboard or gamepad bindings
- settings, rebind, or device-selection logic
- UI focus gating or project-specific business rules
This crate stays narrow on purpose: project code marks cameras with
SwitchableCamera and sends SwitchCameraRequest values.
An optional input_bindings feature adds a minimal Bevy-native input layer.
It stays generic on purpose:
- keyboard via
ButtonInput<KeyCode> - optional native gamepad bindings via Bevy
Gamepad - no control-settings resource
- no rebind workflow
- no primary-device selection
- no UI/business-state gating
Participation Rules
Only entities that have both:
SwitchableCameraCamera
participate in switching. A request targeting a plain Camera, a plain
SwitchableCamera, or any unrelated entity is ignored.
Stable ordering
Candidates always sort by:
order_keyslot.unwrap_or(u8::MAX)- entity index
That same ordering drives cycle behavior and repeated-slot tie breaking.
Request Semantics
SwitchCameraRequest supports four operations:
ToEntity(Entity): switch to the matching switchable camera entityToSlot(u8): switch to the first ordered camera with that slotCycleNext: move forward through the ordered camera listCyclePrev: move backward through the ordered camera list
Behavior details:
- missing targets are a no-op
- cycling with no active camera selects the first ordered candidate
- switching to the already uniquely active camera is a no-op
- if multiple cameras are active, the next valid switch collapses them down to one active camera
CameraSwitched.previousisSome(entity)only when there was exactly one active camera before the switch- when a switch request succeeds, the target camera becomes the only active switchable camera
Usage
Core only
use *;
use ;
new.add_plugins;
Listen for successful switches:
use *;
use CameraSwitched;
input_bindings feature
#
#
Feature-disabled builds still compile only the core switching API.
CameraInputBindingsPlugin emits SwitchCameraRequest messages from generic
keyboard/gamepad bindings before the core switch application runs.
Input-layer details:
- keyboard slot bindings use the first matching
just_pressedkey nextandprevare checked after direct slot bindings- gamepad checks run only if
CameraInputBindings.gamepadis configured - gamepad bindings match any connected gamepad; this feature does not pick a primary device