Skip to content

Commit c0a52d9

Browse files
authored
Reflect GizmoConfigStore (#12104)
# Objective - Make `GizmoConfigStore` play well with reflection-based workflows like editors. ## Solution - `#[derive(Reflect)]` and call `.register_type()`.
1 parent de004da commit c0a52d9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

crates/bevy_gizmos/src/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use crate as bevy_gizmos;
44
pub use bevy_gizmos_macros::GizmoConfigGroup;
55

6-
use bevy_ecs::{component::Component, system::Resource};
7-
use bevy_reflect::{Reflect, TypePath};
6+
use bevy_ecs::{component::Component, reflect::ReflectResource, system::Resource};
7+
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
88
use bevy_render::view::RenderLayers;
99
use bevy_utils::TypeIdMap;
1010
use core::panic;
@@ -27,9 +27,11 @@ pub struct DefaultGizmoConfigGroup;
2727
/// A [`Resource`] storing [`GizmoConfig`] and [`GizmoConfigGroup`] structs
2828
///
2929
/// Use `app.init_gizmo_group::<T>()` to register a custom config group.
30-
#[derive(Resource, Default)]
30+
#[derive(Reflect, Resource, Default)]
31+
#[reflect(Resource, Default)]
3132
pub struct GizmoConfigStore {
3233
// INVARIANT: must map TypeId::of::<T>() to correct type T
34+
#[reflect(ignore)]
3335
store: TypeIdMap<(GizmoConfig, Box<dyn Reflect>)>,
3436
}
3537

crates/bevy_gizmos/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl Plugin for GizmoPlugin {
9898
load_internal_asset!(app, LINE_SHADER_HANDLE, "lines.wgsl", Shader::from_wgsl);
9999

100100
app.register_type::<GizmoConfig>()
101+
.register_type::<GizmoConfigStore>()
101102
.add_plugins(UniformComponentPlugin::<LineGizmoUniform>::default())
102103
.init_asset::<LineGizmo>()
103104
.add_plugins(RenderAssetPlugin::<LineGizmo>::default())

0 commit comments

Comments
 (0)