-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
add example of creating systems via closures #2231
Conversation
could you also add the example to https://github.com/bevyengine/bevy/blob/main/examples/README.md? |
To pass parameters to your systems, you can use a Box::new(|mut cmd: Commands, arg: Local<String>| {
info!("this system uses the moved arg: {:?}", arg);
let id = cmd.spawn().id();
info!("also it spawned an entity {:?}", id);
})
.system()
.config(|config| config.1 = Some("hello".to_string())) |
Thanks for the review!
Interesting, I didn't know about this. Do you think this PR is still useful as an example? (cc @alice-i-cecile) |
Yes! We don't show how to pass closures as system, so that's valuable. And it would be even more with the |
info!("this system uses an argument: {:?}", arg); | ||
let id = cmd.spawn().id(); | ||
info!("also it spawned an entity {:?}", id); | ||
}).system().config(|config| config.1 = Some("hello".to_string()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}).system().config(|config| config.1 = Some("hello".to_string()))) | |
}).system()) |
Unless the .config()
is completely necessary here, I feel like it's just adding unnecessary noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is necessary -- that's what sets the Local<String>
.
The content itself looks solid, it but could use a bit more motivating text at the start, explaining why you might want to do this. |
Just to make sure I'm understanding -- should I add a comment/text to the example, or do you mean add more explanation to the PR description? |
The former please; it's much more important that end users can understand the motivation. And the reviewers can check the comments in the code ;) |
sorry for dropping this! will try to wrap it up by the end of this week. |
as seen on Discord, |
#2422 should help with that. |
Closing due to no response on relicensing. |
Closing to let someone else pick this work up :) Please credit the author of this PR if you build off it. |
Prompted by this discord discussion.
This example shows how to pass an arbitrary argument to a closure, and how to then use that closure as a
bevy_ecs::system::System
.