Trait bevy::ecs::prelude::DetectChanges
[−]pub trait DetectChanges {
fn is_added(&self) -> bool;
fn is_changed(&self) -> bool;
fn set_changed(&mut self);
fn last_changed(&self) -> u32;
}
Expand description
Types that implement reliable change detection.
Example
Using types that implement DetectChanges
, such as ResMut
, provide
a way to query if a value has been mutated in another system.
Normally change detecting is triggered by either DerefMut
or AsMut
, however
it can be manually triggered via DetectChanges::set_changed
.
use bevy_ecs::prelude::*;
struct MyResource(u32);
fn my_system(mut resource: ResMut<MyResource>) {
if resource.is_changed() {
println!("My resource was mutated!");
}
resource.0 = 42; // triggers change detection via [`DerefMut`]
}
Required Methods
fn is_changed(&self) -> bool
fn is_changed(&self) -> bool
Returns true
if this value was added or mutably dereferenced after the system last ran.
fn set_changed(&mut self)
fn set_changed(&mut self)
Flags this value as having been changed.
Mutably accessing this smart pointer will automatically flag this value as having been changed. However, mutation through interior mutability requires manual reporting.
Note: This operation cannot be undone.
fn last_changed(&self) -> u32
fn last_changed(&self) -> u32
Returns the change tick recording the previous time this component (or resource) was changed.
Note that components and resources are also marked as changed upon insertion.
For comparison, the previous change tick of a system can be read using the
SystemChangeTick
SystemParam
.