bevy_mod_picking icon indicating copy to clipboard operation
bevy_mod_picking copied to clipboard

SceneBundle Example

Open dgriffith0 opened this issue 3 years ago • 1 comments

Would be really useful to have an example of how to get this work for the new SceneBundle. The method I use to use to get this to work was complicated and no longer seems to be working as of 0.8. (Using with_children and calling scene_spawner as the child and passing the returned instance_id off see if its spawned before adding the PickableBundle).

dgriffith0 avatar Aug 03 '22 03:08 dgriffith0

Ended up getting this to work with the code below. If there is any interest in adding this as an example id be willing to create one.

fn add_pickable(
    mut commands: Commands,
    scene_spawner: Res<SceneSpawner>,
    scene_query: Query<(Entity, &SceneInstance, &Tree)>,
) {
    for (scene_entity, scene_instance, _) in scene_query.iter() {
        if let Some(entity_iter) =
            scene_spawner.iter_instance_entities(**scene_instance)
        {
            entity_iter.for_each(|entity| {
                commands
                    .entity(entity)
                    .insert_bundle(PickableBundle::default());
            });

            commands.entity(scene_entity).remove::<SceneInstance>();
        }
    }
}

dgriffith0 avatar Aug 04 '22 01:08 dgriffith0