Skip to content

Commit da31d6e

Browse files
committed
bevy_reflect: Remove ReflectSerialize and ReflectDeserialize registrations from most glam types (#6580)
# Objective > Part of #6573 When serializing a `DynamicScene` we end up treating almost all non-value types as though their type data doesn't exist. This is because when creating the `DynamicScene` we call `Reflect::clone_value` on the components, which generates a Dynamic type for all non-value types. What this means is that the `glam` types are treated as though their `ReflectSerialize` registrations don't exist. However, the deserializer _does_ pick up the registration and attempts to use that instead. This results in the deserializer trying to operate on "malformed" data, causing this error: ``` WARN bevy_asset::asset_server: encountered an error while loading an asset: Expected float ``` ## Solution Ideally, we should better handle the serialization of possibly-Dynamic types. However, this runs into issues where the `ReflectSerialize` expects the concrete type and not a Dynamic representation, resulting in a panic: https://github.com/bevyengine/bevy/blob/0aa4147af6d583c707863484d6a8ad50ed0ed984/crates/bevy_reflect/src/type_registry.rs#L402-L413 Since glam types are so heavily used in Bevy (specifically in `Transform` and `GlobalTransform`), it makes sense to just a quick fix in that enables them to be used properly in scenes while a proper solution is found. This PR simply removes all `ReflectSerialize` and `ReflectDeserialize` registrations from the glam types that are reflected as structs. --- ## Changelog - Remove `ReflectSerialize` and `ReflectDeserialize` registrations from most glam types ## Migration Guide This PR removes `ReflectSerialize` and `ReflectDeserialize` registrations from most glam types. This means any code relying on either of those type data existing for those glam types will need to not do that. This also means that some serialized glam types will need to be updated. For example, here is `Affine3A`: ```rust // BEFORE ( "glam::f32::affine3a::Affine3A": (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0), // AFTER "glam::f32::affine3a::Affine3A": ( matrix3: ( x_axis: ( x: 1.0, y: 0.0, z: 0.0, ), y_axis: ( x: 0.0, y: 1.0, z: 0.0, ), z_axis: ( x: 0.0, y: 0.0, z: 1.0, ), ), translation: ( x: 0.0, y: 0.0, z: 0.0, ), ) ) ```
1 parent 3827316 commit da31d6e

File tree

1 file changed

+11
-11
lines changed
  • crates/bevy_reflect/src/impls

1 file changed

+11
-11
lines changed

crates/bevy_reflect/src/impls/glam.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,30 @@ impl_reflect_struct!(
139139
);
140140

141141
impl_reflect_struct!(
142-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
142+
#[reflect(Debug, PartialEq, Default)]
143143
struct Mat2 {
144144
x_axis: Vec2,
145145
y_axis: Vec2,
146146
}
147147
);
148148
impl_reflect_struct!(
149-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
149+
#[reflect(Debug, PartialEq, Default)]
150150
struct Mat3 {
151151
x_axis: Vec3,
152152
y_axis: Vec3,
153153
z_axis: Vec3,
154154
}
155155
);
156156
impl_reflect_struct!(
157-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
157+
#[reflect(Debug, PartialEq, Default)]
158158
struct Mat3A {
159159
x_axis: Vec3A,
160160
y_axis: Vec3A,
161161
z_axis: Vec3A,
162162
}
163163
);
164164
impl_reflect_struct!(
165-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
165+
#[reflect(Debug, PartialEq, Default)]
166166
struct Mat4 {
167167
x_axis: Vec4,
168168
y_axis: Vec4,
@@ -172,22 +172,22 @@ impl_reflect_struct!(
172172
);
173173

174174
impl_reflect_struct!(
175-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
175+
#[reflect(Debug, PartialEq, Default)]
176176
struct DMat2 {
177177
x_axis: DVec2,
178178
y_axis: DVec2,
179179
}
180180
);
181181
impl_reflect_struct!(
182-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
182+
#[reflect(Debug, PartialEq, Default)]
183183
struct DMat3 {
184184
x_axis: DVec3,
185185
y_axis: DVec3,
186186
z_axis: DVec3,
187187
}
188188
);
189189
impl_reflect_struct!(
190-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
190+
#[reflect(Debug, PartialEq, Default)]
191191
struct DMat4 {
192192
x_axis: DVec4,
193193
y_axis: DVec4,
@@ -197,29 +197,29 @@ impl_reflect_struct!(
197197
);
198198

199199
impl_reflect_struct!(
200-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
200+
#[reflect(Debug, PartialEq, Default)]
201201
struct Affine2 {
202202
matrix2: Mat2,
203203
translation: Vec2,
204204
}
205205
);
206206
impl_reflect_struct!(
207-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
207+
#[reflect(Debug, PartialEq, Default)]
208208
struct Affine3A {
209209
matrix3: Mat3A,
210210
translation: Vec3A,
211211
}
212212
);
213213

214214
impl_reflect_struct!(
215-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
215+
#[reflect(Debug, PartialEq, Default)]
216216
struct DAffine2 {
217217
matrix2: DMat2,
218218
translation: DVec2,
219219
}
220220
);
221221
impl_reflect_struct!(
222-
#[reflect(Debug, PartialEq, Serialize, Deserialize, Default)]
222+
#[reflect(Debug, PartialEq, Default)]
223223
struct DAffine3 {
224224
matrix3: DMat3,
225225
translation: DVec3,

0 commit comments

Comments
 (0)