Skip to content
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,24 @@ impl World {
result
}

/// Sends an [Event](crate::event::Event).
#[inline]
pub fn send_event<E: crate::event::Event>(&mut self, event: E) {
match self.get_resource_mut::<crate::event::Events<E>>() {
Some(mut events) => events.send(event),
None => bevy_utils::tracing::error!(
"Unable to send event `{}`\n\tEvent must be added to the app with `add_event()`\n\thttps://docs.rs/bevy/*/bevy/app/struct.App.html#method.add_event ",
std::any::type_name::<E>()
),
}
}

/// Sends the default value of the [Event](crate::event::Event) of type `E`.
#[inline]
pub fn send_default_event<E: crate::event::Event + Default>(&mut self) {
self.send_event(E::default());
}

/// # Safety
/// `component_id` must be assigned to a component of type `R`
#[inline]
Expand Down