Skip to content

feat: script system ordering by label/set and run conditions - #650

Open
makspll wants to merge 6 commits into
agent/script-systems-read-accessfrom
agent/script-systems-scheduling
Open

makspll wants to merge 6 commits into
agent/script-systems-read-accessfrom
agent/script-systems-scheduling

Conversation

@makspll

@makspll makspll commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Stacked on #648. Third of the script system PRs.

Ordering

  • :after_script_system(label, attachment) / :before_script_system(..) order against another script's system. The (attachment, label) pair is resolved through ScriptSystems to that system's slot set. The other system must already exist, otherwise add_system returns an error.
  • :in_set(name) / :after_set(name) / :before_set(name): a name resolves to a Rust set the game registered with app.register_script_system_set(name, set) (ScriptSystemSetRegistry), otherwise to ScriptNamedSet(name), which scripts share to group their systems. Each distinct name is interned once.
  • Every resolved set is recorded in orders_against, so a slot isn't recycled while another system orders against it.

Run conditions

  • bms.conditions is a namespace value holding the ScriptRunCondition type, the same way bms.world holds World. Its static functions build conditions: resource_exists, resource_changed, resource_added, any_with_component, on_timer(secs), run_once, not_, and_, or_. The combinators end in _ because not, and and or are Lua keywords.
  • :run_if(c) stacks; all conditions must hold.
  • Conditions are evaluated by ScriptConditionSystem, a ReadOnlySystem passed to Bevy's run_if. It declares exactly what it reads:
    • resources: add_resource_read
    • any_with_component: a With<C> query's access
    • on_timer: a read of Time
  • Resources are entities in Bevy 0.20, so resource_changed / resource_added read change ticks through resource_entities() and get_change_ticks_by_id. Every top-level condition is evaluated each run, so timers keep ticking. and_ / or_ short-circuit, like Bevy's combinators.
  • New dependencies: bevy_time in core, for on_timer; bevy_mod_scripting_bindings_domain in functions, for the namespace value's type info.

Tests

  • Lua: ordering by script system and by named set (checks both the schedule graph and the actual run order), every condition and combinator, and the errors for a missing script system and for a negative timer interval.
  • Rust: resource_changed across runs, on_timer with an advanced Time, ordering against a registered Rust set.

🤖 Generated with Claude Code

@makspll
makspll added this pull request to stack #649 October 22, 2026 15:40
@semanticdiff-com

semanticdiff-com Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/bevy_mod_scripting_bindings/src/builtins.rs  40% smaller
  crates/bevy_system_reflection/src/lib.rs  35% smaller
  crates/bevy_mod_scripting_bindings/src/script_component.rs  17% smaller
  crates/bevy_mod_scripting_functions/src/core.rs  6% smaller
  crates/bevy_mod_scripting_bindings/src/world_extensions.rs  4% smaller
  crates/bevy_mod_scripting_core/src/script_system.rs  4% smaller
  AGENTS.md Unsupported file format
  assets/definitions/bindings.d.lua Unsupported file format
  assets/tests/add_system/run_conditions.lua  0% smaller
  assets/tests/add_system/systems_order_by_script_system_and_set.lua  0% smaller
  assets/tests/export_reload/lua/caller.lua  0% smaller
  assets/tests/export_reload/lua/exporter.lua  0% smaller
  assets/tests/export_reload/rune/caller.rn Unsupported file format
  assets/tests/export_reload/rune/exporter.rn Unsupported file format
  crates/bevy_mod_scripting_bindings/src/lib.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/system_set.rs  0% smaller
  crates/bevy_mod_scripting_core/Cargo.toml Unsupported file format
  crates/bevy_mod_scripting_functions/Cargo.toml Unsupported file format
  crates/bindings/bevy_mod_scripting_bevy_asset_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_camera_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_gizmos_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_input_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_text_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_time_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_transform_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_ui_bindings/src/lib.rs  0% smaller
  crates/bindings/bevy_mod_scripting_bevy_window_bindings/src/lib.rs  0% smaller
  docs/src/ReleaseNotes/0.23-to-0.24.md Unsupported file format
  docs/src/ScriptSystems/introduction.md Unsupported file format

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectBevy Scripting
Branchagent/script-systems-scheduling
Testbedlinux-gha

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

- `after_script_system` / `before_script_system` order against another
  script's system by (label, attachment), resolved through ScriptSystems
- `in_set` / `after_set` / `before_set` take set names: sets registered with
  `app.register_script_system_set(name, set)`, otherwise a ScriptNamedSet
- `run_if` with `bms.conditions` (resource_exists/changed/added,
  any_with_component, on_timer, run_once, not_/and_/or_), evaluated in Rust
  by a read only condition system declaring its accesses
@makspll
makspll force-pushed the agent/script-systems-scheduling branch from b73748e to 80cacf2 Compare October 23, 2026 12:07
…tems-scheduling

# Conflicts:
#	crates/bevy_mod_scripting_core/src/script_system.rs
…s in script namespaces, Rust ones as namespace members
…tems-scheduling

# Conflicts:
#	docs/src/ReleaseNotes/0.23-to-0.24.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant