[Merged by Bors] - bevy_reflect: Fix DynamicScene not respecting component registrations during serialization#6288
Conversation
|
is there an easier way to catch this kind of issues? Should |
We could do that. But the issue in this particular case was that the actual value ( I don't think there's any way to prevent this from happening, though. We can't really override Footnotes
|
|
bors r+ |
…ns during serialization (#6288) # Objective When running the scene example, you might notice we end up printing out the following: ```ron // ... { "scene::ComponentB": ( value: "hello", _time_since_startup: ( secs: 0, nanos: 0, ), ), }, // ... ``` We should not be printing out `_time_since_startup` as the field is marked with `#[reflect(skip_serializing)]`: ```rust #[derive(Component, Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(skip_serializing)] pub _time_since_startup: Duration, } ``` This is because when we create the `DynamicScene`, we end up calling `Reflect::clone_value`: https://github.com/bevyengine/bevy/blob/82126697ee4f635cf6b22e0b9f25e5aca95fda4a/crates/bevy_scene/src/dynamic_scene_builder.rs#L114-L114 This results in non-Value types being cloned into Dynamic types, which means the `TypeId` returned from `reflected_value.type_id()` is not the same as the original component's. And this meant we were not able to locate the correct `TypeRegistration`. ## Solution Use `TypeInfo::type_id()` instead of calling `Any::type_id()` on the value directly. --- ## Changelog * Fix a bug introduced in `0.9.0-dev` where scenes disregarded component's type registrations
|
Build failed (retrying...): |
…ns during serialization (#6288) # Objective When running the scene example, you might notice we end up printing out the following: ```ron // ... { "scene::ComponentB": ( value: "hello", _time_since_startup: ( secs: 0, nanos: 0, ), ), }, // ... ``` We should not be printing out `_time_since_startup` as the field is marked with `#[reflect(skip_serializing)]`: ```rust #[derive(Component, Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(skip_serializing)] pub _time_since_startup: Duration, } ``` This is because when we create the `DynamicScene`, we end up calling `Reflect::clone_value`: https://github.com/bevyengine/bevy/blob/82126697ee4f635cf6b22e0b9f25e5aca95fda4a/crates/bevy_scene/src/dynamic_scene_builder.rs#L114-L114 This results in non-Value types being cloned into Dynamic types, which means the `TypeId` returned from `reflected_value.type_id()` is not the same as the original component's. And this meant we were not able to locate the correct `TypeRegistration`. ## Solution Use `TypeInfo::type_id()` instead of calling `Any::type_id()` on the value directly. --- ## Changelog * Fix a bug introduced in `0.9.0-dev` where scenes disregarded component's type registrations
DynamicScene not respecting component registrations during serializationDynamicScene not respecting component registrations during serialization
…ns during serialization (bevyengine#6288) # Objective When running the scene example, you might notice we end up printing out the following: ```ron // ... { "scene::ComponentB": ( value: "hello", _time_since_startup: ( secs: 0, nanos: 0, ), ), }, // ... ``` We should not be printing out `_time_since_startup` as the field is marked with `#[reflect(skip_serializing)]`: ```rust #[derive(Component, Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(skip_serializing)] pub _time_since_startup: Duration, } ``` This is because when we create the `DynamicScene`, we end up calling `Reflect::clone_value`: https://github.com/bevyengine/bevy/blob/82126697ee4f635cf6b22e0b9f25e5aca95fda4a/crates/bevy_scene/src/dynamic_scene_builder.rs#L114-L114 This results in non-Value types being cloned into Dynamic types, which means the `TypeId` returned from `reflected_value.type_id()` is not the same as the original component's. And this meant we were not able to locate the correct `TypeRegistration`. ## Solution Use `TypeInfo::type_id()` instead of calling `Any::type_id()` on the value directly. --- ## Changelog * Fix a bug introduced in `0.9.0-dev` where scenes disregarded component's type registrations
…ns during serialization (bevyengine#6288) # Objective When running the scene example, you might notice we end up printing out the following: ```ron // ... { "scene::ComponentB": ( value: "hello", _time_since_startup: ( secs: 0, nanos: 0, ), ), }, // ... ``` We should not be printing out `_time_since_startup` as the field is marked with `#[reflect(skip_serializing)]`: ```rust #[derive(Component, Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(skip_serializing)] pub _time_since_startup: Duration, } ``` This is because when we create the `DynamicScene`, we end up calling `Reflect::clone_value`: https://github.com/bevyengine/bevy/blob/82126697ee4f635cf6b22e0b9f25e5aca95fda4a/crates/bevy_scene/src/dynamic_scene_builder.rs#L114-L114 This results in non-Value types being cloned into Dynamic types, which means the `TypeId` returned from `reflected_value.type_id()` is not the same as the original component's. And this meant we were not able to locate the correct `TypeRegistration`. ## Solution Use `TypeInfo::type_id()` instead of calling `Any::type_id()` on the value directly. --- ## Changelog * Fix a bug introduced in `0.9.0-dev` where scenes disregarded component's type registrations
…ns during serialization (bevyengine#6288) # Objective When running the scene example, you might notice we end up printing out the following: ```ron // ... { "scene::ComponentB": ( value: "hello", _time_since_startup: ( secs: 0, nanos: 0, ), ), }, // ... ``` We should not be printing out `_time_since_startup` as the field is marked with `#[reflect(skip_serializing)]`: ```rust #[derive(Component, Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(skip_serializing)] pub _time_since_startup: Duration, } ``` This is because when we create the `DynamicScene`, we end up calling `Reflect::clone_value`: https://github.com/bevyengine/bevy/blob/82126697ee4f635cf6b22e0b9f25e5aca95fda4a/crates/bevy_scene/src/dynamic_scene_builder.rs#L114-L114 This results in non-Value types being cloned into Dynamic types, which means the `TypeId` returned from `reflected_value.type_id()` is not the same as the original component's. And this meant we were not able to locate the correct `TypeRegistration`. ## Solution Use `TypeInfo::type_id()` instead of calling `Any::type_id()` on the value directly. --- ## Changelog * Fix a bug introduced in `0.9.0-dev` where scenes disregarded component's type registrations
Objective
When running the scene example, you might notice we end up printing out the following:
We should not be printing out
_time_since_startupas the field is marked with#[reflect(skip_serializing)]:This is because when we create the
DynamicScene, we end up callingReflect::clone_value:bevy/crates/bevy_scene/src/dynamic_scene_builder.rs
Line 114 in 8212669
This results in non-Value types being cloned into Dynamic types, which means the
TypeIdreturned fromreflected_value.type_id()is not the same as the original component's.And this meant we were not able to locate the correct
TypeRegistration.Solution
Use
TypeInfo::type_id()instead of callingAny::type_id()on the value directly.Changelog
0.9.0-devwhere scenes disregarded component's type registrations