Conversation
This method lets us access `Commands` directly while in the `with_children` method. This is useful if you're doing something like inserting resources associated to one of the children entities.
|
|
|
I agree with @Ixentus and imagine that this could be quite confusing. In the case of your documentation example, I think it would be clearer to remember the entity and insert the resource later on after spawning. |
|
While this doesn't expose anything that's not already possible through I would prefer to have specialised functions on the |
|
Would it help if the method name said it wasn't attached to the parent? Something like And yes, this doesn't formally add anything that For my use case, I think storing the entity in a local to run after the fact breaks the locality of reading, making it harder to understand what the code is doing. The declared local, setting the local, and then actually inserting the resource with the local will all be in completely different locations. Like, they are multiple screens away. |
There's something to be said for both "make the hard things hard" and "there should be only one way to do things". I think Ixentus raises an important point about the confusion this could induce. In general I'm not thrilled with the level of mental hoops required to work with |
|
So if I understand correctly, you're adding Commands to the Childbuilder to use Commands inside it. However you can trivially do this by adding a second mut Commands to the system parameters: fn setup_locations(mut commands: Commands, mut commandsb: Commands) {
commands
.spawn()
.insert(Transform::from_xyz(1.0, 0.0, 0.0))
.insert(GlobalTransform::default())
.with_children(|parent| {
let entity = parent
.spawn()
.insert(Transform::from_xyz(1.0, 0.0, 0.0))
.insert(GlobalTransform::default())
.id();
commandsb.insert_resource(ImportantLocation(entity));
});
}I'm not sure this is even documented though, so this PR made sense :) |
| /// Calling [`spawn`][Commands::spawn] or [`spawn_bundle`][Commands::spawn_bundle] on the | ||
| /// returned value will **not** insert the parent and children components. |
There was a problem hiding this comment.
This seems like a footgun waiting to happen...
There was a problem hiding this comment.
It's a footgun on the already-present add_commands method.
|
I don't forsee this being approved, so I'm going to close it. Do note that the underlying motivation is still there, and that |
Objective
Access the
Commandsdirectly from within awith_childrenclosure.Solution
Add a
.commands()method toChildBuilderto accessCommandsdirectly.