bevyengine / bevyengine/bevy

Entities spawned with `Disabled` do not render when `Disabled` is removed

Open
#18,981 5 comments 6 reactions 0 assignees View on GitHub
A-Cross-Cutting A-Rendering C-Bug D-Complex S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.16.0

## What you did

Spawn an Entity with a mesh and the `Disabled` component. Remove the component later.

## What went wrong

The mesh will not render.

## Additional information

Minimal reproduction:
- Left click should make the mesh appear but it does not.
- Removing the `Disabled` component from the spawn command, and running the sample again, clicking (right+left) does properly hide/show the mesh.

```rust
use bevy::{ecs::entity_disabling::Disabled, prelude::*};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, on_click)
.run();
}

fn setup(
mut cmd: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
cmd.spawn((
Mesh3d(meshes.add(Sphere::new(0.5))),
MeshMaterial3d(materials.add(Color::srgb(1., 0., 0.))),
Transform::from_xyz(0., 0., -2.),
Disabled,
));

cmd.spawn(Camera3d::default());
}

fn on_click(
mut cmd: Commands,
buttons: Res>,
mesh_entity: Single<(Entity, Has), With>,
) {
if buttons.just_pressed(MouseButton::Left) {
info!("Removing Disabled");
cmd.entity(mesh_entity.0).remove::();
}
if buttons.just_pressed(MouseButton::Right) {
info!("Inserting Disabled");
cmd.entity(mesh_entity.0).insert(Disabled);
}
}
```

Guesswork: I suppose that adding `Disabled` as a spawn component for the entity prevents the rendering systems to pick up on it and to properly extract it to the render world ? And removing the `Disabled` component later probably does not trigger a change detection picked up by the render world.

Contributor guide

Open the contributing guide

Research direction

Start with the minimal Rust reproduction and the ecs::entity_disabling::Disabled entry point, then trace the rendering systems involved when an entity is spawned disabled and when Disabled is removed. Verify the fix by confirming that the mesh appears after the left-click removal and can be hidden and shown again with the right- and left-click sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.