#Can you create a ChildBuilder from Children?

4 messages · Page 1 of 1 (latest)

limpid obsidian
#

When an event happens I run an update system that will spawn some sprites on top of a base sprite.

The function that I would like to use, uses a ChildBuilder in relation to the parent/base sprite.

Can I run this as a bevy system, if so how would I query and build a "ChildBuilder" that would be needed?

Something like this?
mut lands: Query< (&mut TextureAtlasSprite, &Location, &Children), (With<Land>, Without<BuildingStructure>), >,

then somehow extract the Children and make a child builder? Not sure if it's possible.

exotic pewter
#

@limpid obsidian
This ChildBuilder: https://docs.rs/bevy/latest/bevy/hierarchy/struct.ChildBuilder.html ?
This is basically a "Commands" made to spawn children relative to a parent, but here from what I understand you already have children spawned, you won't get a ChildBuilder that is both relative to the parent and the already created child, so I don't really understand why you would need a ChildBuilder...
Can we have more details to which function you want to use?
But anyway, if you have a mut commands: Commands and you change your query to Query<(Entity, &mut TextureAtlasSprite, &Location, &Children), (With<Land>, Without<BuildingStructure>)>, you can then do commands.entity(parent_entity).with_children(|child_builder_relative_to_this_parent_entity| /*do your thing here*/)

limpid obsidian
#

@exotic pewter I'm spawning a parent sprite. and I was using that parent sprite as a point of reference for it's children.

So in other words the childbuilder needs a parent sprite to know where to spawn stuff .. the translation x/y is done from the relative point of the parent.
I have made a function to help modularize my code, and 1 of the parameters is a childbuilder .. but if I want other parts of my code to also spawn these child sprites then i need the relevant childbuilder for the given parent.

So i was wondering if I could spawn these children sprites if I could query for the parent and produce the childbuilder needed for the function param that i want to call.

I think what you posted may work.. let me give it a try.

#

btw.. worked like a charm.. thank you very much 🙂 i was struggling with this for many hours