-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useS-Nominated-To-CloseA triage team member thinks this PR or issue should be closed out.A triage team member thinks this PR or issue should be closed out.
Description
What problem does this solve or what need does it fill?
1.disentanglement.
2.enhance flexibility.
3.Reduce world exclusive time.
What solution would you like?
Such:
let entity = world.spawn_empty();
world.register_system_by_entity(entity,intosystem);
register_system_by_entity function:
pub fn register_system_by_entity<I, O>(
&mut self,
entity: Entity,
system: BoxedSystem<I, O>,
) -> SystemId<I, O>
where
I: SystemInput + 'static,
O: 'static,
{
self.entity_mut(entity)
.insert(RegisteredSystem::new(system));
SystemId::from_entity(entity)
}
What alternative(s) have you considered?
not
Additional context
The common method to obtain SystemId is through system exclusive world:
fn usually(world:&mut World){
let systemid = world.register_system(system);
...
}
If the above method is supported,
fn support(
mut commands: Commands, //Or ParallelCommands
...
) {
let empty = commands.spawn_empty().id();
// It is necessary to ensure that the type corresponds to the system
let systemid: SystemId<(), ()> = SystemId::from_entity(empty);
commands.queue(|world:&mut World|{
let world_systemid = world.register_system_by_entity(empty,system);
//You can do some checks
assert_eq!(systemid,world_systemid);
});
// For example, certain components may run unique systems
// However, the current system ID has not been fully successfully registered
#[derive(Debug, Component)]
struct Component1(SystemId<(), ()>);
commands.spawn(Component1(systemid));
}
I conducted some tests on the SystemId of the current version (0.16.1)
let mut world = World::new();
let empty = world.spawn_empty().id();
let systemid = SystemId::<(), ()>::from_entity(empty);
let result = world.run_system(systemid);
assert!(result.is_err());
println!("{:?}", result);
println:
Err(Recursive(SystemId(0v1#4294967296)))
let systemid: SystemId<(), bool> = world.register_system(|| -> bool { true });
let result = world.run_system(systemid);
assert!(result.is_ok());
let entity = systemid.entity();
// Modified type parameters
let systemid = SystemId::<(), ()>::from_entity(entity);
let result = world.run_system(systemid);
assert!(result.is_err());
println:
Err(Recursive(SystemId(1v1#4294967297)))
World can identify which systemid are valid.
Overall, I believe that the text should be supported.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useS-Nominated-To-CloseA triage team member thinks this PR or issue should be closed out.A triage team member thinks this PR or issue should be closed out.