Open
Description
What problem does this solve or what need does it fill?
It's occasionally useful to be able to temporarily "disable" an observer. In many cases, this can be trivially achieved by despawning (and then later re-spawning) Observer
entities. However, this is not a general solution.
If the observer is a capturing closure that may mutate its captured state, despawning it will thrash the state. In generic contexts, this would also require a Clone
bound on the observer. You can work around this currently, but it's a little cumbersome.
What solution would you like?
Ideally, the Disabled
component would prevent an Observer
in the same entity from running.
Additional context
Here's a quick demonstration of the current state:
use bevy::{ecs::entity_disabling::Disabled, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, startup)
.run();
}
fn startup(mut commands: Commands) {
commands.spawn(Observer::new(|trigger: Trigger<OnAdd, Transform>| {
info!("normal observer: added transform to {:?}", trigger.target());
}));
commands.spawn((
Observer::new(|trigger: Trigger<OnAdd, Transform>| {
info!(
"disabled observer: added transform to {:?}",
trigger.target()
);
}),
Disabled,
));
commands.spawn(Transform::default());
}
As is, this outputs two logs:
normal observer: added transform to 7v1#4294967303
disabled observer: added transform to 7v1#4294967303
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Observer overhaul