-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Callback
as Asset
#10711
base: main
Are you sure you want to change the base?
Callback
as Asset
#10711
Conversation
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
I'm really excited about this idea: this matches up with how I think systems-from-disk should work, and is great for enabling behaviorful objects on disk, both in UI and in the context of things like scripted objects (doors, traps,...). Before we merge this, definitely want a strong example and ideally some module-level docs. |
@@ -3,15 +3,41 @@ use crate::system::{BoxedSystem, Command, IntoSystem}; | |||
use crate::world::World; | |||
use crate::{self as bevy_ecs}; | |||
use bevy_ecs_macros::Component; | |||
use bevy_reflect::TypePath; | |||
use thiserror::Error; | |||
|
|||
/// A small wrapper for [`BoxedSystem`] that also keeps track whether or not the system has been initialized. |
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.
Remember to update these docs.
Hmm... I didn't mean to make any breaking changes. This is meant to only be additive. How do I see what they are? |
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.
Hard to fully evaluate without docs, but initial impressions:
- I don't understand why
Callback
stores anOption
. - I don't understand why we need the extra layer of abstraction with
DriveSystem
. - Not sure that the
RunCallback
type alias will be useful. - We should compare and contrast for the asset-based approach in the one_shot_systems example, where we make our own code-only callback type.
- Definitely needs tests and examples that validate this in the context of a data-driven workflow.
Architecture and core idea seem good though!
@alice-i-cecile Thanks for the initial feedback.
|
Sounds good :) Definitely continue with this architecture then; I'm sure it'll be clearer as it gets better documented. |
Yeah, this doesn't actually appear to have any breaking changes. Initially I thought we already had a first-party |
Changing out the one shot system example Callback for this one could serve as a good proof of concept. |
I added an example. It might be too complex but I feel like it demonstrates the feature well. |
Because this MR has landed, I was able to simplify the logic and get rid of that internal One draw back is that it is no longer possible to detect recursive calls which might make it harder to debug recursive calls. I have added a test that worked with the old implementation but now fails. I feel like this implementation is far better so I'm OK with this trade off but we might want to think if we want to add some APIs to |
I'm unsure this is the right direction with the closure of #10582. I do agree that observers are probably the better solution. I will also include some of my thoughts about the callback approach here.
|
Objective
Make managing one shot systems easier.
Addresses concerns brought up in #10582 and #10426.
Solution
Models
Callback
s asAsset
s. This allows calling systems throughHandle
s.This is largely pulled from an implementation from my own game and I'm happy with the ergonomics.
This approach has many advantages:
&mut World
System
s are automatically cleaned up when no more strongHandle
s exist.System
s could be loaded in using asset loaders (I have already started experimenting with this).Callback
s which will be helpful ifCallback
s are used with UI.But does have some disadvantages:
Callback
s must implementTypePath
.Asset
trait.Callback
(new combination of input and output), the user must callapp.init_asset::<Callback<I, O>>()
.&mut Assets<Callback<I, O>>
is required to create aHandle
. This a double edge sword.spawn
calls. But you can't in-line the creation of a callback in another callback.Callback
s require differentAssets
types to createHandle
s.Alternatives explored before landing on this implementation:
SystemId
internally inCallback
&mut World
to createSystemId
Command
to create them and aMutex
to update the internal state of theCallback
once theCommand
was runArc<Mutex<...>>
inCallback
and not useHandle
s.Callbacks
extremely easy.Callback
s in Scenes.I'm creating this as a Draft to gather feedback and see if others think that the tradeoffs and implementation make sense.
TODO:
Changelog
TODO