-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrongThis issue requires detective work to figure out what's going wrong
Description
Bevy version and features
- 0.18.0 (repro'd on main at cf35f37)
What you did
Created a custom 1:1 relationship, and spawned entities using EntityCommands::with_related:
#[derive(Component)]
#[relationship(relationship_target = MyFriend)]
struct FriendOf(pub Entity);
#[derive(Component)]
#[relationship_target(relationship = FriendOf)]
struct MyFriend(Entity);Spawning entities:
fn spawning(mut commands: Commands) {
let mut top_entity_command = commands.spawn_empty();
// Bugged Behavior
top_entity_command.with_related::<FriendOf>(Bugged);
// Workaround
let top_entity_id = top_entity_command.id();
commands.spawn((FriendOf(top_entity_id), NotBugged));
}
// Marker Trait
#[derive(Component)]
struct Bugged;
// Marker Trait
#[derive(Component)]
struct NotBugged;What went wrong
Using .with_related::<FriendOf>() doesn't insert the FriendOf component on the source entity.
fn verify(
bugged: Single<Has<FriendOf>, With<Bugged>>,
not_bugged: Single<Has<FriendOf>, With<NotBugged>>,
) {
// Prints "false"
println!("Bugged:\t\t{}", bugged.into_inner());
// Prints "true"
println!("Not bugged:\t{}", not_bugged.into_inner());
}Additional information
This seems to be specific to 1:1 relationships (i.e. impl RelationshipSourceCollection for Entity). If I change the relationship target to be a Vec<Entity>, there is no bug. E.g.
-- struct MyFriend(Entity);
++ struct MyFriend(Vec<Entity>);With the above diff, then the verify system returns "true" and "true"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrongThis issue requires detective work to figure out what's going wrong