logo
pub trait DetectChanges {
    fn is_added(&self) -> bool;
    fn is_changed(&self) -> bool;
    fn set_changed(&mut self);
}
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

Returns true if (and only if) this value been added since the last execution of this system.

Returns true if (and only if) this value been changed since the last execution of this system.

Manually flags this value as having been changed. This normally isn’t required because accessing this pointer mutably automatically flags this value as “changed”.

Note: This operation is irreversible.

Implementors