Skip to content

Commit 43b859d

Browse files
Implements conversion from SystemId to Entity (#11759)
# Objective Right now when using egui, systems are inserted without any identifier and to the root. I'd like to name those systems and insert them as children to a root entity. This helps to keep the editor organized. ## Solution - Although the `SystemId` is documented as an opaque type, examples depicted above benefit from tear down of the abstraction. --- ## Changelog ### Added - Implemented `From<SystemId>` for `Entity` --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent 78b6fa1 commit 43b859d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

crates/bevy_ecs/src/system/system_registry.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ impl<I, O> std::fmt::Debug for SystemId<I, O> {
7474
}
7575
}
7676

77+
impl<I, O> From<SystemId<I, O>> for Entity {
78+
/// Transforms a [`SystemId`] into the [`Entity`] that holds the one-shot system's state.
79+
///
80+
/// It's trivial to convert [`SystemId`] into an [`Entity`] since a system
81+
/// is really an entity with associated handler function.
82+
///
83+
/// For example, this is useful if you want to assign a name label to a system.
84+
fn from(SystemId(entity, _): SystemId<I, O>) -> Self {
85+
entity
86+
}
87+
}
88+
7789
impl World {
7890
/// Registers a system and returns a [`SystemId`] so it can later be called by [`World::run_system`].
7991
///
@@ -83,7 +95,7 @@ impl World {
8395
/// because the [`SystemId`] that is returned can be used anywhere in the [`World`] to run the associated system.
8496
/// This allows for running systems in a pushed-based fashion.
8597
/// Using a [`Schedule`](crate::schedule::Schedule) is still preferred for most cases
86-
/// due to its better performance and abillity to run non-conflicting systems simultaneously.
98+
/// due to its better performance and ability to run non-conflicting systems simultaneously.
8799
pub fn register_system<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>(
88100
&mut self,
89101
system: S,

0 commit comments

Comments
 (0)