Closed Jondolf closed 1 week ago
let mut world = World::new();
world.register_required_components::<B, C>();
let result = world.try_register_required_components::<A, B>();
assert!(result.is_ok());
let id = world.spawn(B).id();
assert!(world.entity(id).get::<C>().is_some());
The first assertion actually fails, so the problem seems to be with the attempt to register the required component.
DuplicateRegistration(ComponentId(6), ComponentId(4))
That one is supposed to return an error (hence why I used try_
) since the requirement is already defined earlier with #[require(B)]
. It's not related to the issue where the requirement for A -> C
isn't added correctly
This isn't fully resolved by #16410:
#[test]
fn runtime_required_components_propagate_up_multiple() {
#[derive(Component)]
struct A;
#[derive(Component, Default)]
struct B;
#[derive(Component, Default)]
struct C;
#[derive(Component, Default)]
struct D;
let mut world = World::new();
world.register_required_components::<A, B>();
world.register_required_components::<B, C>();
world.register_required_components::<C, D>();
let id = world.spawn(A).id();
assert!(world.entity(id).get::<B>().is_some());
assert!(world.entity(id).get::<C>().is_some());
assert!(world.entity(id).get::<D>().is_some());
}
Bevy version
Bevy 0.15.0-rc.3
What you did
I have a component, let's say
A
, that requires another componentB
using#[require(B)]
.B
then requires another componentC
, but the requirement is registered in a plugin usingapp.register_required_components::<B, C>()
.What went wrong
When I spawn an entity with
A
,C
is not added!Here's a simple test that fails:
If the entity is spawned with
B
directly, it does work:This implies that the problem is related to runtime requirements not being properly propagated up the inheritance tree if the higher levels use
#[require(...)]
, or if the higher level requirement is added after the lower level requirement.