-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reflection: Add distinction between ignoring fields for purposes of scene deserialization and external visibility #5245
Comments
The issue is that while they’re conceptually coupled, the derive and the serialization don’t really communicate with each other directly. We have use the registry to drive serde stuff (and adding another trait won't help much without the registry). So it's going to be difficult to make specific fields reflectable but not serializable. One solution might be to add a map in the registry that maps field name/index to a Boolean flag indicating whether the field can be serialized or not ( It would probably be easier to just mark the entire struct (i.e. the field's type) with an attribute that prevents serialization. Then we don't need a map or need to worry about "name vs index," but it's debatable whether that would truly be better (personally, I think it makes more sense for the original type to determine if it's serializable or not) and match most use cases. |
Disabling serialisation for an entire type would be fairly rigid, and you never know if a type might need to be serialised in another context. And yeah, I don't really see another solution short of keeping track of indices/field names. |
… automatic serialization (#5250) # Objective - To address problems outlined in #5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `ReflectSerializableWithData` trait for retrieving `SerializationData` which is implemented via macros - `SerializationData` structure for describing which fields are to be/not to be ignored - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
… automatic serialization (#5250) # Objective - To address problems outlined in #5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
… automatic serialization (bevyengine#5250) # Objective - To address problems outlined in bevyengine#5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
… automatic serialization (bevyengine#5250) # Objective - To address problems outlined in bevyengine#5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
… automatic serialization (bevyengine#5250) # Objective - To address problems outlined in bevyengine#5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
What problem does this solve or what need does it fill?
This stems from a discussion on discord.
Currently the reflection system is closely coupled with scene serialisation. This unavoidably causes the propagation of
#[reflect(ignore)]
's throughout the codebase on fields which:An example of this can be seen in
bevy::render::Camera
:in this example
RenderTarget
should not be hidden away from for example script users or the editor. There is tension between goals 1. and 3.What solution would you like?
Separate the notions of ignoring fields from reflection and just serialization,
perhaps an attribute like:
#[reflect(dont_scene_serialize)]
would help make the intent clearer and solve the tension between two different use cases.
What alternative(s) have you considered?
The text was updated successfully, but these errors were encountered: