Skip to content

Allow entities to be added to a relationship using the new spawn api #18961

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

Closed
wants to merge 6 commits into from

Conversation

Freyja-moth
Copy link
Contributor

@Freyja-moth Freyja-moth commented Apr 27, 2025

Objective

Fixes #18662

Useful if you want to to add something that already exists to a relationship .

Solution

Added SpawnEntity and SpawnEntites which implement SpawnableList.

I also added SpawnIter and SpawnWith to bevy_ecs's prelude as it felt weird that they'd be missing, but maybe there's some reason why they weren't added? If you know anything about it lmk.

I'm also not entirely sold on the names so if anyone has any better ideas lmk.

Testing

Tested by adding a child using the new methods and checking if it exists, and it worked! First try!

Showcase

let child1 = commands.spawn(Name::new("Child1")).id();

commands.spawn((
    Name::new("Root"),
    Children::spawn((
        SpawnEntity(child1),
    )),
));

@grind086
Copy link
Contributor

Maybe SpawnedEntity/SpawnedEntities to indicate that they're already spawned. Or something like WithRelated.

@ickshonpe ickshonpe added A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 29, 2025
@Freyja-moth Freyja-moth closed this by deleting the head repository May 3, 2025
@BenjaminBrienen
Copy link
Contributor

Update PR description code example with new terminology

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding an entity using a RelationshipTarget
4 participants