Open
Description
Bevy version
Bevy v0.16.0.
What you did
Tried to reflect-deserialize a type containing HashMap<TileId, ...>
where:
#[derive(Component, Debug, Clone, Deserialize, Eq, PartialEq, Hash, Reflect)]
#[component(immutable)]
pub struct TileId(Cow<'static, str>);
Specifically I have data stored in an asset and do:
- Parse asset into data representation (think
json::Value
). - Use
TypedReflectDeserializer
to deserialize the value. <-- this is where it all goes wrong - Use
T::from_reflect(value.as_partial_reflect())
to get the final type.
What went wrong
Received this panic:
bevy_reflect-0.16.0/src/map.rs:259:30:
the dynamic type `bevy_reflect::DynamicTupleStruct` (representing `game_core::map::data::TileId`) does not support hashing
Additional information
- Adding
#[reflect(Hash)]
did not change the error, but adding#[reflect(Hash, Deserialize)]
does fix it. - Switching to
TileId(String)
did not change the error. - Removing
#[component(immutable)]
did not change the error.
The bug seems to be that when TileId
is represented as DynamicTupleStruct
, its hashability is lost unless you do #[reflect(Hash, Deserialize)]
. At minimum we need a better error message to give people a solution.