mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
Prevent event from getting registered twice (#4258)
# Objective As described in #4257, registering an Event twice would cause some systems to miss events on some starts, since the event buffer is cleared + swapped multiple times. Fixes #4257 ## Solution A simple check whether the event is already registered is added, making adding an Event a second time a no-op.
This commit is contained in:
parent
b0ddce36bd
commit
cd694c0d08
1 changed files with 5 additions and 2 deletions
|
@ -622,8 +622,11 @@ impl App {
|
|||
where
|
||||
T: Resource,
|
||||
{
|
||||
self.init_resource::<Events<T>>()
|
||||
.add_system_to_stage(CoreStage::First, Events::<T>::update_system)
|
||||
if !self.world.contains_resource::<Events<T>>() {
|
||||
self.init_resource::<Events<T>>()
|
||||
.add_system_to_stage(CoreStage::First, Events::<T>::update_system);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.
|
||||
|
|
Loading…
Reference in a new issue