Trait bevy_ecs::change_detection::DetectChanges
source · pub trait DetectChanges {
// Required methods
fn is_added(&self) -> bool;
fn is_changed(&self) -> bool;
fn last_changed(&self) -> u32;
}
Expand description
Types that can read change detection information.
This change detection is controlled by DetectChangesMut
types such as ResMut
.
Example
Using types that implement DetectChanges
, such as Res
, provide
a way to query if a value has been mutated in another system.
use bevy_ecs::prelude::*;
#[derive(Resource)]
struct MyResource(u32);
fn my_system(mut resource: Res<MyResource>) {
if resource.is_changed() {
println!("My component was mutated!");
}
}
Required Methods§
sourcefn is_changed(&self) -> bool
fn is_changed(&self) -> bool
Returns true
if this value was added or mutably dereferenced after the system last ran.
sourcefn last_changed(&self) -> u32
fn last_changed(&self) -> u32
Returns the change tick recording the time this data was most recently 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
.