Enum AnimationEvent

Source
pub enum AnimationEvent {
    MarkerHit {
        entity: Entity,
        marker_id: AnimationMarkerId,
        animation_id: AnimationId,
        animation_repetition: usize,
        clip_id: ClipId,
        clip_repetition: usize,
    },
    ClipRepetitionEnd {
        entity: Entity,
        animation_id: AnimationId,
        clip_id: ClipId,
        clip_repetition: usize,
    },
    ClipEnd {
        entity: Entity,
        animation_id: AnimationId,
        clip_id: ClipId,
    },
    AnimationRepetitionEnd {
        entity: Entity,
        animation_id: AnimationId,
        animation_repetition: usize,
    },
    AnimationEnd {
        entity: Entity,
        animation_id: AnimationId,
    },
}
Expand description

A Bevy event emitted when an animation reaches a point of interest

  • when a clip repetition ends
  • when a clip ends (if the clip repeats multiple times, only occurs at the end of the last repetition)
  • when an animation repetition ends
  • when an animation ends (if the animation repeats multiple times, only occurs at the end of the last repetition)
  • when an animation marker is hit

§Example

You can use those events to be notified of a clip/animation ending.

fn death_transition_system(
    mut events: EventReader<AnimationEvent>,
    library: Res<AnimationLibrary>
) {
    for event in events.read() {
        match event {
            // Some animation just ended...
            AnimationEvent::AnimationEnd { animation_id, .. } => {
                // ... it was the main character's death animation,
                // we can go back to the main menu

                if library.is_animation_name(*animation_id, "character dies") {
                    go_to_main_menu();
                }
            }
            // Ignore other events
            _ => (),
        }
    }
}

§Example

You can also add markers to specific frames of a clip to be notified of an animation reaching points of interest.

// Let's create a marker to be notified when the exact frame
// of the character shooting their gun is played
let marker_id = library.new_marker();

// Naming a marker is not required but it can be convenient to refer to it later
// if you don't want to keep its ID around
library.name_marker(marker_id, "bullet goes out");

let clip = Clip::from_frames([10, 11, 15, 16, 17])
    // The character shoots their gun on the fourth frame
    .with_marker(marker_id, 3);
// We can watch events from any system and react to them
fn spawn_visual_effects_system(
    mut events: EventReader<AnimationEvent>,
    library: Res<AnimationLibrary>
) {
    for event in events.read() {
        match event {
            // Some marker was just hit...
            AnimationEvent::MarkerHit { marker_id, .. } => {
                // ... it was our "bullet goes out" marker, let's spawn a bullet.

                if library.is_marker_name(*marker_id, "bullet goes out") {
                    spawn_bullet();
                }
            }
            // Ignore other events
            _ => (),
        }
    }
}

Variants§

§

MarkerHit

An animation marker has been hit

Fields

§entity: Entity
§animation_id: AnimationId
§animation_repetition: usize
§clip_id: ClipId
§clip_repetition: usize
§

ClipRepetitionEnd

A repetition of a clip has ended

Fields

§entity: Entity
§animation_id: AnimationId
§clip_id: ClipId
§clip_repetition: usize
§

ClipEnd

An clip ended

Fields

§entity: Entity
§animation_id: AnimationId
§clip_id: ClipId
§

AnimationRepetitionEnd

A repetition of an animation has ended

Fields

§entity: Entity
§animation_id: AnimationId
§animation_repetition: usize
§

AnimationEnd

An animation has ended

Fields

§entity: Entity
§animation_id: AnimationId

Trait Implementations§

Source§

impl Clone for AnimationEvent

Source§

fn clone(&self) -> AnimationEvent

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnimationEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

const AUTO_PROPAGATE: bool = false

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

type Traversal = ()

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

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

Generates the ComponentId for this event type. Read more
Source§

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

Fetches the ComponentId for this event type, if it has already been generated. Read more
Source§

impl Hash for AnimationEvent

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AnimationEvent

Source§

fn eq(&self, other: &AnimationEvent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for AnimationEvent

Source§

impl Eq for AnimationEvent

Source§

impl StructuralPartialEq for AnimationEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,