Skip to content

Commit 7c59317

Browse files
authored
Fix bevy_picking plugin suffixes (bevyengine#16082)
# Objective - `MeshPickingBackend` and `SpritePickingBackend` do not have the `Plugin` suffix - `DefaultPickingPlugins` is masquerading as a `Plugin` when in reality it should be a `PluginGroup` - Fixes bevyengine#16081. ## Solution - Rename some structures: |Original Name|New Name| |-|-| |`MeshPickingBackend`|`MeshPickingPlugin`| |`MeshPickingBackendSettings`|`MeshPickingSettings`| |`SpritePickingBackend`|`SpritePickingPlugin`| |`UiPickingBackendPlugin`|`UiPickingPlugin`| - Make `DefaultPickingPlugins` a `PluginGroup`. - Because `DefaultPickingPlugins` is within the `DefaultPlugins` plugin group, I also added support for nested plugin groups to the `plugin_group!` macro. ## Testing - I used ripgrep to ensure all references were properly renamed. - For the `plugin_group!` macro, I used `cargo expand` to manually inspect the expansion of `DefaultPlugins`. --- ## Migration Guide > [!NOTE] > > All 3 of the changed structures were added after 0.14, so this does not need to be included in the 0.14 to 0.15 migration guide. - `MeshPickingBackend` is now named `MeshPickingPlugin`. - `MeshPickingBackendSettings` is now named `MeshPickingSettings`. - `SpritePickingBackend` is now named `SpritePickingPlugin`. - `UiPickingBackendPlugin` is now named `UiPickingPlugin`. - `DefaultPickingPlugins` is now a a `PluginGroup` instead of a `Plugin`.
1 parent 611ba8b commit 7c59317

File tree

9 files changed

+82
-31
lines changed

9 files changed

+82
-31
lines changed

crates/bevy_app/src/plugin_group.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ use core::any::TypeId;
4848
/// # impl Plugin for WebCompatibilityPlugin { fn build(&self, _: &mut App) {} }
4949
/// # }
5050
/// #
51+
/// # mod audio {
52+
/// # use bevy_app::*;
53+
/// # #[derive(Default)]
54+
/// # pub struct AudioPlugins;
55+
/// # impl PluginGroup for AudioPlugins {
56+
/// # fn build(self) -> PluginGroupBuilder {
57+
/// # PluginGroupBuilder::start::<Self>()
58+
/// # }
59+
/// # }
60+
/// # }
61+
/// #
5162
/// # mod internal {
5263
/// # use bevy_app::*;
5364
/// # #[derive(Default)]
@@ -75,6 +86,10 @@ use core::any::TypeId;
7586
/// // generation, in which case you must wrap it in `#[custom()]`.
7687
/// #[custom(cfg(target_arch = "wasm32"))]
7788
/// web:::WebCompatibilityPlugin,
89+
/// // You can nest `PluginGroup`s within other `PluginGroup`s, you just need the
90+
/// // `#[plugin_group]` attribute.
91+
/// #[plugin_group]
92+
/// audio:::AudioPlugins,
7893
/// // You can hide plugins from documentation. Due to macro limitations, hidden plugins
7994
/// // must be last.
8095
/// #[doc(hidden)]
@@ -94,6 +109,14 @@ macro_rules! plugin_group {
94109
$(#[custom($plugin_meta:meta)])*
95110
$($plugin_path:ident::)* : $plugin_name:ident
96111
),*
112+
$(
113+
$(,)?$(
114+
#[plugin_group]
115+
$(#[cfg(feature = $plugin_group_feature:literal)])?
116+
$(#[custom($plugin_group_meta:meta)])*
117+
$($plugin_group_path:ident::)* : $plugin_group_name:ident
118+
),+
119+
)?
97120
$(
98121
$(,)?$(
99122
#[doc(hidden)]
@@ -113,6 +136,10 @@ macro_rules! plugin_group {
113136
" - [`", stringify!($plugin_name), "`](" $(, stringify!($plugin_path), "::")*, stringify!($plugin_name), ")"
114137
$(, " - with feature `", $plugin_feature, "`")?
115138
)])*
139+
$($(#[doc = concat!(
140+
" - [`", stringify!($plugin_group_name), "`](" $(, stringify!($plugin_group_path), "::")*, stringify!($plugin_group_name), ")"
141+
$(, " - with feature `", $plugin_group_feature, "`")?
142+
)]),+)?
116143
$(
117144
///
118145
$(#[doc = $post_doc])+
@@ -135,6 +162,18 @@ macro_rules! plugin_group {
135162
group = group.add(<$($plugin_path::)*$plugin_name>::default());
136163
}
137164
)*
165+
$($(
166+
$(#[cfg(feature = $plugin_group_feature)])?
167+
$(#[$plugin_group_meta])*
168+
{
169+
const _: () = {
170+
const fn check_default<T: Default>() {}
171+
check_default::<$($plugin_group_path::)*$plugin_group_name>();
172+
};
173+
174+
group = group.add_group(<$($plugin_group_path::)*$plugin_group_name>::default());
175+
}
176+
)+)?
138177
$($(
139178
$(#[cfg(feature = $hidden_plugin_feature)])?
140179
$(#[$hidden_plugin_meta])*

crates/bevy_internal/src/default_plugins.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ plugin_group! {
5656
bevy_gizmos:::GizmoPlugin,
5757
#[cfg(feature = "bevy_state")]
5858
bevy_state::app:::StatesPlugin,
59-
#[cfg(feature = "bevy_picking")]
60-
bevy_picking:::DefaultPickingPlugins,
6159
#[cfg(feature = "bevy_dev_tools")]
6260
bevy_dev_tools:::DevToolsPlugin,
6361
#[cfg(feature = "bevy_ci_testing")]
6462
bevy_dev_tools::ci_testing:::CiTestingPlugin,
63+
#[plugin_group]
64+
#[cfg(feature = "bevy_picking")]
65+
bevy_picking:::DefaultPickingPlugins,
6566
#[doc(hidden)]
6667
:IgnoreAmbiguitiesPlugin,
6768
}

crates/bevy_picking/src/lib.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub mod input;
160160
pub mod mesh_picking;
161161
pub mod pointer;
162162

163-
use bevy_app::prelude::*;
163+
use bevy_app::{prelude::*, PluginGroupBuilder};
164164
use bevy_ecs::prelude::*;
165165
use bevy_reflect::prelude::*;
166166

@@ -172,7 +172,7 @@ pub mod prelude {
172172
#[doc(hidden)]
173173
pub use crate::mesh_picking::{
174174
ray_cast::{MeshRayCast, RayCastBackfaces, RayCastSettings, RayCastVisibility},
175-
MeshPickingBackend, MeshPickingBackendSettings, RayCastPickable,
175+
MeshPickingPlugin, MeshPickingSettings, RayCastPickable,
176176
};
177177
#[doc(hidden)]
178178
pub use crate::{
@@ -275,15 +275,26 @@ pub enum PickSet {
275275
#[derive(Default)]
276276
pub struct DefaultPickingPlugins;
277277

278-
impl Plugin for DefaultPickingPlugins {
279-
fn build(&self, app: &mut App) {
280-
app.add_plugins((
281-
input::PointerInputPlugin::default(),
282-
PickingPlugin::default(),
283-
InteractionPlugin,
284-
));
278+
impl PluginGroup for DefaultPickingPlugins {
279+
fn build(self) -> PluginGroupBuilder {
280+
#[cfg_attr(
281+
not(feature = "bevy_mesh"),
282+
expect(
283+
unused_mut,
284+
reason = "Group is not mutated when `bevy_mesh` is not enabled."
285+
)
286+
)]
287+
let mut group = PluginGroupBuilder::start::<Self>()
288+
.add(input::PointerInputPlugin::default())
289+
.add(PickingPlugin::default())
290+
.add(InteractionPlugin);
291+
285292
#[cfg(feature = "bevy_mesh")]
286-
app.add_plugins(mesh_picking::MeshPickingBackend);
293+
{
294+
group = group.add(mesh_picking::MeshPickingPlugin);
295+
};
296+
297+
group
287298
}
288299
}
289300

crates/bevy_picking/src/mesh_picking/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! By default, all meshes are pickable. Picking can be disabled for individual entities
44
//! by adding [`PickingBehavior::IGNORE`].
55
//!
6-
//! To make mesh picking entirely opt-in, set [`MeshPickingBackendSettings::require_markers`]
6+
//! To make mesh picking entirely opt-in, set [`MeshPickingSettings::require_markers`]
77
//! to `true` and add a [`RayCastPickable`] component to the desired camera and target entities.
88
//!
99
//! To manually perform mesh ray casts independent of picking, use the [`MeshRayCast`] system parameter.
@@ -21,10 +21,10 @@ use bevy_reflect::prelude::*;
2121
use bevy_render::{prelude::*, view::RenderLayers};
2222
use ray_cast::{MeshRayCast, RayCastSettings, RayCastVisibility, SimplifiedMesh};
2323

24-
/// Runtime settings for the [`MeshPickingBackend`].
24+
/// Runtime settings for the [`MeshPickingPlugin`].
2525
#[derive(Resource, Reflect)]
2626
#[reflect(Resource, Default)]
27-
pub struct MeshPickingBackendSettings {
27+
pub struct MeshPickingSettings {
2828
/// When set to `true` ray casting will only happen between cameras and entities marked with
2929
/// [`RayCastPickable`]. `false` by default.
3030
///
@@ -40,7 +40,7 @@ pub struct MeshPickingBackendSettings {
4040
pub ray_cast_visibility: RayCastVisibility,
4141
}
4242

43-
impl Default for MeshPickingBackendSettings {
43+
impl Default for MeshPickingSettings {
4444
fn default() -> Self {
4545
Self {
4646
require_markers: false,
@@ -49,28 +49,28 @@ impl Default for MeshPickingBackendSettings {
4949
}
5050
}
5151

52-
/// An optional component that marks cameras and target entities that should be used in the [`MeshPickingBackend`].
53-
/// Only needed if [`MeshPickingBackendSettings::require_markers`] is set to `true`, and ignored otherwise.
52+
/// An optional component that marks cameras and target entities that should be used in the [`MeshPickingPlugin`].
53+
/// Only needed if [`MeshPickingSettings::require_markers`] is set to `true`, and ignored otherwise.
5454
#[derive(Debug, Clone, Default, Component, Reflect)]
5555
#[reflect(Component, Default)]
5656
pub struct RayCastPickable;
5757

5858
/// Adds the mesh picking backend to your app.
5959
#[derive(Clone, Default)]
60-
pub struct MeshPickingBackend;
60+
pub struct MeshPickingPlugin;
6161

62-
impl Plugin for MeshPickingBackend {
62+
impl Plugin for MeshPickingPlugin {
6363
fn build(&self, app: &mut App) {
64-
app.init_resource::<MeshPickingBackendSettings>()
65-
.register_type::<(RayCastPickable, MeshPickingBackendSettings, SimplifiedMesh)>()
64+
app.init_resource::<MeshPickingSettings>()
65+
.register_type::<(RayCastPickable, MeshPickingSettings, SimplifiedMesh)>()
6666
.add_systems(PreUpdate, update_hits.in_set(PickSet::Backend));
6767
}
6868
}
6969

70-
/// Casts rays into the scene using [`MeshPickingBackendSettings`] and sends [`PointerHits`] events.
70+
/// Casts rays into the scene using [`MeshPickingSettings`] and sends [`PointerHits`] events.
7171
#[allow(clippy::too_many_arguments)]
7272
pub fn update_hits(
73-
backend_settings: Res<MeshPickingBackendSettings>,
73+
backend_settings: Res<MeshPickingSettings>,
7474
ray_map: Res<RayMap>,
7575
picking_cameras: Query<(&Camera, Option<&RayCastPickable>, Option<&RenderLayers>)>,
7676
pickables: Query<&PickingBehavior>,

crates/bevy_sprite/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Plugin for SpritePlugin {
135135
);
136136

137137
#[cfg(feature = "bevy_sprite_picking_backend")]
138-
app.add_plugins(picking_backend::SpritePickingBackend);
138+
app.add_plugins(picking_backend::SpritePickingPlugin);
139139

140140
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
141141
render_app

crates/bevy_sprite/src/picking_backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use bevy_transform::prelude::*;
1515
use bevy_window::PrimaryWindow;
1616

1717
#[derive(Clone)]
18-
pub struct SpritePickingBackend;
18+
pub struct SpritePickingPlugin;
1919

20-
impl Plugin for SpritePickingBackend {
20+
impl Plugin for SpritePickingPlugin {
2121
fn build(&self, app: &mut App) {
2222
app.add_systems(PreUpdate, sprite_picking.in_set(PickSet::Backend));
2323
}

crates/bevy_ui/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Plugin for UiPlugin {
219219
build_text_interop(app);
220220

221221
#[cfg(feature = "bevy_ui_picking_backend")]
222-
app.add_plugins(picking_backend::UiPickingBackendPlugin);
222+
app.add_plugins(picking_backend::UiPickingPlugin);
223223

224224
if !self.enable_rendering {
225225
return;

crates/bevy_ui/src/picking_backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use bevy_picking::backend::prelude::*;
3636

3737
/// A plugin that adds picking support for UI nodes.
3838
#[derive(Clone)]
39-
pub struct UiPickingBackendPlugin;
40-
impl Plugin for UiPickingBackendPlugin {
39+
pub struct UiPickingPlugin;
40+
impl Plugin for UiPickingPlugin {
4141
fn build(&self, app: &mut App) {
4242
app.add_systems(PreUpdate, ui_picking.in_set(PickSet::Backend));
4343
}

examples/picking/mesh_picking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! By default, all meshes are pickable. Picking can be disabled for individual entities
44
//! by adding [`PickingBehavior::IGNORE`].
55
//!
6-
//! If you want mesh picking to be entirely opt-in, you can set [`MeshPickingBackendSettings::require_markers`]
6+
//! If you want mesh picking to be entirely opt-in, you can set [`MeshPickingSettings::require_markers`]
77
//! to `true` and add a [`RayCastPickable`] component to the desired camera and target entities.
88
99
use std::f32::consts::PI;

0 commit comments

Comments
 (0)