-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What problem does this solve or what need does it fill?
Some operations are only done very rarely: scripting-like game logic that modifies levels, unlocks achievements or handles a boss's special attack come to mind.
These systems clutter the schedule, waste resources as they constantly spin, and are harder to extend.
What solution would you like?
There are two parts to my proposed solution:
- Add
Commands::run_system(system: impl Into<SystemDescriptor>)
. This runs the specified system on theWorld
the next time commands are processed. - Create a pattern where we store references to system functions on components, and dynamically run those systems when the appropriate trigger is met, allowing for scripting-like flexibility with low-overhead and seamless ergonomic Bevy syntax.
What alternative(s) have you considered?
Writing custom commands types each time will be onerous and have much increased boilerplate, and because they take exclusive access to World
, force the users to learn a new syntax and reduce our ability to parallelize commands of this sort in the future.
This same functionality could also be framed as "dynamically inserting systems", but that may complicate the API somewhat when you often don't end up caring a lot about overhead.
Other approaches to reactivity may be able to fill this niche in some form instead.
Additional context
Making sure the ordering on this is correct enough is going to be one of the larger challenges. May be better to wait until after #1375. Chaining also needs some careful thought.
Brought up in response to the following user request:
Is it possible / practical / good practice to pass a function around inside an event? My thought process is an NPC could have an interaction with a very specific procedure following it like opening a secret door across the map or unlocking a new dialogue option with another NPC so much so that having a system that contains every one of these niche interactions inside a match would be rather hideous.
Depending on the efficiency and ergonomics of this, could also be used to support push data-flow for UI (see #254).
Related to #1273.