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 RemovedComponentEntity
where Self: Send + Sync + 'static,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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