Skip to content

feat: ScriptExecutionOrder component to control script execution order on entities #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

CrushedPixel
Copy link
Contributor

@CrushedPixel CrushedPixel commented Jul 8, 2025

Summary

This PR adds a ScriptExecutionOrder component that, when added to entities with ScriptComponent,
specifies the order in which entities are iterated for script traversal.

I require control over script execution order as scripts should be able to build on top of each other's world changes
in a deterministic way.

Example usage:

fn spawn_scripts(mut commands: Commands) {
    commands.spawn((
        ScriptComponent::new(vec!["scripts/mod_a.lua"]),
        ScriptExecutionOrder(2), // runs after mod_b
    ));

    commands.spawn((
        ScriptComponent::new(vec!["scripts/mod_b.lua"]),
        ScriptExecutionOrder(1), // runs before mod_a
    ));
}

Caveats

  • This system doesn't allow ordering of static script execution

Considerations

  • If this approach is viable, I'll be happy to add some tests and benches

Copy link

semanticdiff-com bot commented Jul 8, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/bevy_mod_scripting_core/src/handler.rs  64% smaller
  crates/bevy_mod_scripting_core/src/script.rs  0% smaller

@CrushedPixel
Copy link
Contributor Author

Closing in favor of simply dispatching entity-specific events in order

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