-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Allow entities to be added to a relationship using the new spawn api (remade) #19046
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
base: main
Are you sure you want to change the base?
Conversation
i would have a |
Where should I put the test? In src/spawn.rs or are the tests for the Spawn/SpawnIter/SpawnWith that I should place them with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
yes, it could be on #[cfg(test)]
mod tests {
...
} |
Added the tests, also took the liberty of adding tests for Spawn, SpawnIter, and SpawnWith. |
i would have asserts to check if the |
I'm not all that familiar with working directly with world and got stuck trying to find a way to do it by validating the Children, rather than ChildOf and eventually gave up. Will try that |
|
/// Name::new("Root"), | ||
/// Children::spawn(( | ||
/// Spawn(Name::new("Child1")), | ||
/// WithRelated([child2, child3].into_iter()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this I'm not immediately sure what the inferred generic I is, or how that's determined. Can you add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to check, something like this?
world.spawn((
Name::new("Root"),
Children::spawn((
Spawn(Name::new("Child1")),
// [`I`] here is [`Iterator<Item = Entity>`]
WithRelated([child2, child3].into_iter()),
)),
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, explaining that WithRelated
adds the existing entities as children, inferred due to the Children
type above.
/// A wrapper over an [`Entity`] indicating that an entity should be added. | ||
/// This is intended to be used for hierarchical spawning via traits like [`SpawnableList`] and [`SpawnRelated`]. | ||
/// | ||
/// Also see the [`children`](crate::children) and [`related`](crate::related) macros that abstract over the [`Spawn`] API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs need to crosslink against WithRelated, explaining the differences.
crates/bevy_ecs/src/spawn.rs
Outdated
@@ -133,6 +133,73 @@ impl<R: Relationship, F: FnOnce(&mut RelatedSpawner<R>) + Send + Sync + 'static> | |||
} | |||
} | |||
|
|||
/// A [`SpawnableList`] that adds entities using an iterator of [`Entity`]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a particularly useful description by itself, can you add another line explaining why users might to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks like a nice feature, but I found the docs and motivation hard to follow, even after spending a fair bit of time puzzling over it. We need to make sure that this is clear so users know when to use this new API :)
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Objective
Reopens #18961
Solution
Copy the code
Testing
It worked in the previous pull request
Showcase
See #18961