Skip to content

Commit

Permalink
Improve error message and deduplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Jul 17, 2022
1 parent 62512d5 commit 2a57b6a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,17 +1156,24 @@ impl World {
result
}

/// "Sends" an [event](crate::event).
/// Sends an [Event](crate::event::Event).
#[inline]
pub fn event_send<E: crate::event::Event>(&mut self, event: E) {
self.resource_mut::<crate::event::Events<E>>().send(event);
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).
/// Sends the default value of the [Event](crate::event::Event) of type `E`.
#[inline]
pub fn event_send_default<E: crate::event::Event + Default>(&mut self) {
self.resource_mut::<crate::event::Events<E>>()
.send_default();
pub fn send_default_event<E: crate::event::Event + Default>(&mut self) {
self.send_event(E::default());
}

/// # Safety
Expand Down

0 comments on commit 2a57b6a

Please sign in to comment.