Repository: bevyengine/bevy
File: examples/ecs/state_scoped.rs (Rust)

Code before:
            left: px(0),
            ..default()
        },
        (children![DespawnOnExit(GameState::A)]),
    ));
}

fn on_a_exit(mut commands: Commands) {
    info!("on_a_exit");
    commands.spawn((
        DespawnOnEnter(GameState::A),
        Text::new("Game state 'A' will be back in 1 second"),
        TextFont {
            font_size: 33.0,
            ..default()
        },
        TextColor(Color::srgb(0.5, 0.5, 1.0)),
        Node {
            position_type: PositionType::Absolute,
            top: px(0),
            left: px(500),
            ..default()
        },
        // You can apply this even when the parent has a state scope
        // It is unnecessary but in complex hierarchies
        // it saves you from having to mentally track which components are found at the top level
        (children![DespawnOnEnter(GameState::A)]),
    ));
}

fn on_b_enter(mut commands: Commands) {
    info!("on_b_enter");
    commands.spawn((
        DespawnOnExit(GameState::B),
        Text::new("Game is in state 'B'"),
        TextFont {
            font_size: 33.0,
            ..default()
        },
        TextColor(Color::srgb(0.5, 0.5, 1.0)),
        Node {
            position_type: PositionType::Absolute,
            top: px(50),
            left: px(0),
            ..default()
        },
        (children![DespawnOnExit(GameState::B)]),
    ));
}

fn on_b_exit(mut commands: Commands) {

Review comment (suggestion):
```suggestion
        // You can apply this even when the parent has a state scoped component.
        // It is unnecessary but in complex hierarchies it saves you from having to
        // mentally track which components are found at the top level.
```

Code after:
            top: px(0),
            left: px(0),
            ..default()
        },
        (children![DespawnOnExit(GameState::A)]),
    ));
}

fn on_a_exit(mut commands: Commands) {
    info!("on_a_exit");
    commands.spawn((
        DespawnOnEnter(GameState::A),
        Text::new("Game state 'A' will be back in 1 second"),
        TextFont {
            font_size: 33.0,
            ..default()
        },
        TextColor(Color::srgb(0.5, 0.5, 1.0)),
        Node {
            position_type: PositionType::Absolute,
            top: px(0),
            left: px(500),
            ..default()
        },
        // You can apply this even when the parent has a state scoped component.
        // It is unnecessary but in complex hierarchies it saves you from having to
        // mentally track which components are found at the top level.
        (children![DespawnOnEnter(GameState::A)]),
    ));
}

fn on_b_enter(mut commands: Commands) {
    info!("on_b_enter");
    commands.spawn((
        DespawnOnExit(GameState::B),
        Text::new("Game is in state 'B'"),
        TextFont {
            font_size: 33.0,
            ..default()
        },
        TextColor(Color::srgb(0.5, 0.5, 1.0)),
        Node {
            position_type: PositionType::Absolute,
            top: px(50),
            left: px(0),
            ..default()
        },
        (children![DespawnOnExit(GameState::B)]),
    ));
}