From 1b1934f4fbee04510f366abb2c240d9d5adf75c1 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:49:54 +0200 Subject: [PATCH] Fix `CameraProjectionPlugin` not implementing `Plugin` in some cases (#11766) # Objective `CameraProjectionPlugin`'s bounds are `T: CameraProjection`. But the bounds for `CameraProjectionPlugin` implementing `Plugin` are `T: CameraProjection + Component + GetTypeRegistration`. This means that if `T` is valid for `CameraProjectionPlugin`'s bounds, but not the plugin implementation's bounds, then `CameraProjectionPlugin` would not implement `Plugin`. Which is weird because you'd expect a struct with `Plugin` in the name to implement `Plugin`. ## Solution Make `CameraProjectionPlugin`'s bounds `T: CameraProjection + Component + GetTypeRegistration`. I also rearranged some of the code. --- ## Changelog - Changed `CameraProjectionPlugin`'s bounds to `T: CameraProjection + Component + GetTypeRegistration` ## Migration Guide `CameraProjectionPlugin`'s trait bounds now require `T` to implement `CameraProjection`, `Component`, and `GetTypeRegistration`. This shouldn't affect most existing code as `CameraProjectionPlugin` never implemented `Plugin` unless those bounds were met. --- crates/bevy_render/src/camera/projection.rs | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index 4ac5c6d3be..225fd15b77 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -12,20 +12,9 @@ use bevy_transform::components::GlobalTransform; use serde::{Deserialize, Serialize}; /// Adds [`Camera`](crate::camera::Camera) driver systems for a given projection type. -pub struct CameraProjectionPlugin(PhantomData); - -impl Default for CameraProjectionPlugin { - fn default() -> Self { - Self(Default::default()) - } -} - -/// Label for [`camera_system`], shared across all `T`. -/// -/// [`camera_system`]: crate::camera::camera_system -#[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)] -pub struct CameraUpdateSystem; - +pub struct CameraProjectionPlugin( + PhantomData, +); impl Plugin for CameraProjectionPlugin { fn build(&self, app: &mut App) { app.register_type::() @@ -49,6 +38,17 @@ impl Plugin for CameraPro ); } } +impl Default for CameraProjectionPlugin { + fn default() -> Self { + Self(Default::default()) + } +} + +/// Label for [`camera_system`], shared across all `T`. +/// +/// [`camera_system`]: crate::camera::camera_system +#[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)] +pub struct CameraUpdateSystem; /// Trait to control the projection matrix of a camera. ///