Skip to content

Commit

Permalink
Expose resource change detection on World (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRawMeatball committed Mar 24, 2021
1 parent 1c573de commit 10ef750
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,20 @@ impl World {
unsafe { self.get_resource_with_id(component_id) }
}

pub fn is_resource_added<T: Component>(&self) -> bool {
let component_id = self.components.get_resource_id(TypeId::of::<T>()).unwrap();
let column = self.get_populated_resource_column(component_id).unwrap();
let ticks = unsafe { &*column.get_ticks_mut_ptr() };
ticks.is_added(self.last_change_tick(), self.read_change_tick())
}

pub fn is_resource_changed<T: Component>(&self) -> bool {
let component_id = self.components.get_resource_id(TypeId::of::<T>()).unwrap();
let column = self.get_populated_resource_column(component_id).unwrap();
let ticks = unsafe { &*column.get_ticks_mut_ptr() };
ticks.is_changed(self.last_change_tick(), self.read_change_tick())
}

/// Gets a mutable reference to the resource of the given type, if it exists. Otherwise returns
/// [None] Resources are "unique" data of a given type.
#[inline]
Expand Down

0 comments on commit 10ef750

Please sign in to comment.