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
@ -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 New Issue
Block a user