Crate bevy_spawn_observer

Crate bevy_spawn_observer 

Source
Expand description

This crate provides SpawnObserver, a custom SpawnableList enabling you to add observers to your bundles.

use bevy::{ecs::spawn::SpawnWith, prelude::*};
use bevy_spawn_observer::SpawnObserver;

// With `bevy_spawn_observer`:
fn button_new() -> impl Bundle {
    (
        Button,
        Children::spawn(SpawnObserver::new(|_: Trigger<Pointer<Click>>| {
            info!("You clicked me!");
        })),
    )
}

// Without `bevy_spawn_observer`:
fn button_old() -> impl Bundle {
    (
        Node::default(),
        Children::spawn(SpawnWith(|parent: &mut ChildSpawner| {
            parent.spawn(Button).observe(|_: Trigger<Pointer<Click>>| {
                info!("You clicked me!");
            });
        })),
    )
}

See a full example here.

Structsยง

SpawnObserver
A SpawnableList that spawns an Observer as a child entity.