Replies: 1 comment
-
Would you know how to do this nowadays? I don't understand why your code snippets would work (or what exactly they do) and it seems to me like Edit: I've found the Bevy Migration Guides mentioning this.
In my case, the external type ( /// A Wrapper-Type to support [Reflect] on a [geo::Polygon]
#[derive(Reflect, serde::Serialize, serde::Deserialize, Clone)]
#[reflect(opaque)]
pub struct GeoPolygon{
inner: geo::Polygon,
} I have not yet really been able to test this, but it compiles. |
Beta Was this translation helpful? Give feedback.
-
Hello. I'm raising this topic to follow up on discussion on the community Discord. When trying to use scenes to save and load my world state (as part of a save game system) I ran into quite a few issues caused by difficulties in making sure all the types in my components implement
Reflect
.For my structs which contain only types which have the a
Reflect
impl created inbevy_reflect
, there are no issues with using the typical#[derive(Reflect)]
. But I ran into a lot of trouble when trying to get things to work components containing external types. Examples include:Reflect
impl.Decimal
from therust_decimal
crate, which I was using to store high-precision numeric values in some components.std.rs
inbevy_reflect
.VecDeque
fromstd::collections
would probably need a manual impl but doesn't have one.Reflect
orDefault
/FromWorld
Entity
has aReflect
impl via macro but noDefault
/FromWorld
. Quite possibly putting entities in components like this causes an entirely different set of different problems, but ignoring that for now...Concrete examples and workarounds(?)
There may be solutions to some or all of the above, but based on my meagre experience they are quite difficult and/or unintuitive.
For example, for point (1) above, I was, with the help of a very knowledgeable Discord member, able to get Decimal to serialize with the following incantation:
In this example I can use DecimalWrapper as a component which can be serialized successfully. However if I uncomment the first
// #[reflect(Component)]
and try to serialize that struct directly, it fails at runtime with a rather cryptic"Type 'DecimalComponent' does not support ReflectValue serialization"
. I assume there is a variant of this incantation to get it working, but at this point I think it's fair to say we're over the average user's head, and certainly way over mine...I was also able to get the above working by editing
bevy_reflect
locally to depend onrust_decimal
and calling the macro directly from there to avoid the coherence restrictions which prevent me from invoking the macro from my crate:Again this worked but I once again needed help from the very smart people on Discord to figure out the correct trait parameters here, as my naive attempts to simply call
impl_reflect_value!(Decimal)
did not work.Returning to the wrapper solution above though, I figured perhaps this "newtype wrapper for a type which implements
Serialize
andDeserialize
" might solve my problems for all the external types I'm using so I proceeded to attempt to craft a generic wrapper, but my attempts there failed so miserably they are not worth sharing.Points of discussion
I raise these issues not because I have any solution in mind but primarily to share my experience as a user whose experience went from smooth sailing to "trait hell" upon attempting to implement a save system. But to humbly raise some points for discussion:
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions