bevyengine / bevyengine/bevy

Allow registering one-shot system in bsn!

Open
#24,002 0 comments 0 reactions 0 assignees View on GitHub
A-ECS A-Scenes C-Feature D-Modest S-Needs-Design X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

Allow registering and storing one-shot system enables a decoupled way triggering callbacks.

For example, a Button will do some stuff on `Pointer`, and it can also be triggered by pressing "A" button from gamepad when "focused".

```rust
bsn! {
Button
...
on(|ev: On>, mut command: Commands, buttons: Query<&Action>| {
buttons
.get(ev.entity)
.map(|Action(action)| {
command.run_system(*action);
})
.unwrap();
})
...
}

// and in the system handling focused button
fn trigger_focused_button(..., buttons: Query<&Action> ) {
// the logic to get current focused button
// ...

let focused_button = ... // the focused button entity

buttons
.get(focused_button)
.map(|_, Action(action)| {
command.run_system(*action);
})
.unwrap();
}
```

## What solution would you like?

```rust
bsn! {
Button
Action(callback_system) // helper function may needed
}

#[derive(Component, FromTemplate)]
struct Action(SystemId);

fn callback_system(...) { ... }
```

Register once or per scene?

Contributor guide

Open the contributing guide

Research direction

Start at the bsn! macro and the Commands::run_system API shown in the examples. Trace how an Action(SystemId) component could be registered and stored, then clarify whether registration should happen once or per scene. Done means the requested one-shot callback can be declared in bsn! and triggered through the stored system ID.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.