Skip to content

Reflection doesn't work for AnimationPlayer #18701

Closed
@anlumo

Description

@anlumo

Bevy version

main branch

What you did

I'm trying to get my scripting integration to generate animations.

For this, I have to instantiate the AnimationPlayer component:

#[derive(Component, Default, Reflect)]
#[reflect(Component, Default, Clone)]
pub struct AnimationPlayer {
active_animations: HashMap<AnimationNodeIndex, ActiveAnimation>,
}

Note that this struct uses AnimationNodeIndex as the key, which is reflected manually in this file:

impl_reflect_opaque!(::petgraph::graph::NodeIndex(
Clone,
Default,
Serialize,
Deserialize
));

What went wrong

When I create the DynamicMap for the DynamicStruct to recreate AnimationPlayer, I get the following panic:

thread 'render_task' panicked at /home/anlumo/bevy/crates/bevy_reflect/src/map.rs:323:9:
assertion `left == right` failed: keys inserted in `Map`-like types are expected to reflect `PartialEq`
  left: None
 right: Some(true)

The assert is located here:

assert_eq!(
key.reflect_partial_eq(&*key),
Some(true),
"keys inserted in `Map`-like types are expected to reflect `PartialEq`"
);

This happens while inserting into the DynamicMap, and the debug print of the key inserted is Reflect(petgraph::graph::NodeIndex).

Additional information

AnimationNodeIndex maps to petgraph's NodeIndex<u32> (as indicated in the debug output). This is just a newtype around u32, so PartialEq would be trivial. However, I think the macro impl_reflect_opaque! used in petgraph.rs might not add that one automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions