Trait Event

Source
pub trait Event:
    Send
    + Sync
    + 'static {
    type Traversal: Traversal<Self>;

    const AUTO_PROPAGATE: bool = false;

    // Provided methods
    fn register_component_id(world: &mut World) -> ComponentId { ... }
    fn component_id(world: &World) -> Option<ComponentId> { ... }
}
Expand description

Something that “happens” and might be read / observed by app logic.

Events can be stored in an Events<E> resource You can conveniently access events using the EventReader and EventWriter system parameter.

Events can also be “triggered” on a World, which will then cause any Observer of that trigger to run.

Events must be thread-safe.

§Derive

This trait can be derived. Adding auto_propagate sets Self::AUTO_PROPAGATE to true. Adding traversal = "X" sets Self::Traversal to be of type “X”.

use bevy_ecs::prelude::*;

#[derive(Event)]
#[event(auto_propagate)]
struct MyEvent;

Provided Associated Constants§

Source

const AUTO_PROPAGATE: bool = false

When true, this event will always attempt to propagate when triggered, without requiring a call to Trigger::propagate.

Required Associated Types§

Source

type Traversal: Traversal<Self>

The component that describes which Entity to propagate this event to next, when propagation is enabled.

Provided Methods§

Source

fn register_component_id(world: &mut World) -> ComponentId

Generates the ComponentId for this event type.

If this type has already been registered, this will return the existing ComponentId.

This is used by various dynamically typed observer APIs, such as World::trigger_targets_dynamic.

§Warning

This method should not be overridden by implementors, and should always correspond to the implementation of component_id.

Source

fn component_id(world: &World) -> Option<ComponentId>

Fetches the ComponentId for this event type, if it has already been generated.

This is used by various dynamically typed observer APIs, such as World::trigger_targets_dynamic.

§Warning

This method should not be overridden by implementors, and should always correspond to the implementation of register_component_id.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Event for GamepadEvent
where GamepadEvent: Send + Sync + 'static,

Source§

impl Event for GamepadRumbleRequest
where GamepadRumbleRequest: Send + Sync + 'static,

Source§

impl Event for RawGamepadEvent
where RawGamepadEvent: Send + Sync + 'static,

Source§

impl Event for AppExit
where AppExit: Send + Sync + 'static,

Source§

impl Event for GamepadAxisChangedEvent
where GamepadAxisChangedEvent: Send + Sync + 'static,

Source§

impl Event for GamepadButtonChangedEvent
where GamepadButtonChangedEvent: Send + Sync + 'static,

Source§

impl Event for GamepadButtonStateChangedEvent

Source§

impl Event for GamepadConnectionEvent
where GamepadConnectionEvent: Send + Sync + 'static,

Source§

impl Event for RawGamepadAxisChangedEvent

Source§

impl Event for RawGamepadButtonChangedEvent

Source§

impl Event for DoubleTapGesture
where DoubleTapGesture: Send + Sync + 'static,

Source§

impl Event for PanGesture
where PanGesture: Send + Sync + 'static,

Source§

impl Event for PinchGesture
where PinchGesture: Send + Sync + 'static,

Source§

impl Event for RotationGesture
where RotationGesture: Send + Sync + 'static,

Source§

impl Event for KeyboardFocusLost
where KeyboardFocusLost: Send + Sync + 'static,

Source§

impl Event for KeyboardInput
where KeyboardInput: Send + Sync + 'static,

Source§

impl Event for MouseButtonInput
where MouseButtonInput: Send + Sync + 'static,

Source§

impl Event for MouseMotion
where MouseMotion: Send + Sync + 'static,

Source§

impl Event for MouseWheel
where MouseWheel: Send + Sync + 'static,

Source§

impl Event for OnAdd
where OnAdd: Send + Sync + 'static,

Source§

impl Event for OnInsert
where OnInsert: Send + Sync + 'static,

Source§

impl Event for OnRemove
where OnRemove: Send + Sync + 'static,

Source§

impl Event for OnReplace
where OnReplace: Send + Sync + 'static,

Source§

impl Event for TouchInput
where TouchInput: Send + Sync + 'static,

Source§

impl Event for RemovedComponentEntity
where RemovedComponentEntity: Send + Sync + 'static,

Source§

impl Event for OnDespawn
where OnDespawn: Send + Sync + 'static,