-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Bevy version and features
0.18.0, 2d and ui features
Relevant system information
Arch Linux
AdapterInfo { name: "NVIDIA GeForce RTX 4070 Ti", vendor: 4318, device: 10114, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "590.48.01", backend: Vulkan }
What you did
Spawned a mesh with the Disabled component, and had another system enable the entity.
use bevy::{color::palettes::tailwind::CYAN_400, ecs::entity_disabling::Disabled, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, toggle_disabled)
.run();
}
fn toggle_disabled(
mut query: Query<(Entity, Has<Disabled>), With<Mesh2d>>,
keyboard: Res<ButtonInput<KeyCode>>,
mut commands: Commands,
) {
if keyboard.just_pressed(KeyCode::Space) {
for (entity, disabled) in &mut query {
if disabled {
info!("Enabling entity {:?}", entity);
commands.entity(entity).remove::<Disabled>();
} else {
info!("Disabling entity {:?}", entity);
commands.entity(entity).insert(Disabled);
}
}
}
}
fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
) {
commands.spawn(Camera2d);
commands.spawn((
Mesh2d(meshes.add(Rectangle::new(50.0, 50.0))),
MeshMaterial2d(materials.add(Color::from(CYAN_400))),
Disabled,
));
}What went wrong
Nothing is rendered, even after toggling Disabled several times.
It does however log the messages correctly.
2026-01-25T22:41:21.258025Z INFO bevy_winit::system: Creating new window disabling_test (0v0)
2026-01-25T22:41:22.293863Z INFO disabling_test: Disabling entity 14v0
2026-01-25T22:41:22.643608Z INFO disabling_test: Enabling entity 14v0
2026-01-25T22:41:22.909841Z INFO disabling_test: Disabling entity 14v0
2026-01-25T22:41:23.160041Z INFO disabling_test: Enabling entity 14v0
2026-01-25T22:41:23.360308Z INFO disabling_test: Disabling entity 14v0
2026-01-25T22:41:23.560014Z INFO disabling_test: Enabling entity 14v0
If I don't add Disabled at spawn, it is rendered like expected:
and it is hidden and shown again when toggling Disabled by pressing Space.
Additional information
I ran into this in an Avian example. It was rendering my immediate-mode debug rendering gizmos for the collider, and the physics entity was still being simulated, but the mesh was not visible. I have not tested if this was working before 0.18.
It also doesn't seem like a problem with required components. I checked, and the entity had a Transform given by Mesh2d even when the entity was spawned as disabled.