Extend existing bundle? #1217
Replies: 3 comments
-
I could also do something like this: #[derive(Bundle)]
struct BuildingBundle {
pub pos: BuildingPos,
}
fn building_bundles(
...
) -> (SpriteBundle, BuildingBundle) {
...
}
let (a, b) = building_bundles(...);
commands.spawn(a).with_bundle(b); If I added a custom trait I could give commands a function like |
Beta Was this translation helpful? Give feedback.
-
From that question, it seems like you're looking to organize logic, not data, so maybe instead of looking to custom data structures, consider using a helper function instead? fn spawn_building(commands: &mut Commands, ...) {
...
commands.spawn(SpriteBundle {
material: materials.add(texture_handle.into()),
..Default::default()
})
.with(BuildingPos { ... });
} Does that seem like what you were looking for? |
Beta Was this translation helpful? Give feedback.
-
See #792 and follow-up discussion :) The bundle nesting tech described in #1570 should solve your specific need here. |
Beta Was this translation helpful? Give feedback.
-
I have a situation where I want to spawn an entity that is a sprite with a couple of extra components. Right now I am doing it like this:
Is there a way to use the existing definition of
SpriteBundle
and then addBuildingPos
to it?Beta Was this translation helpful? Give feedback.
All reactions