Skip to content

TypePath required for generic #[reflect(ignore)] field #9094

@paul-hansen

Description

@paul-hansen

Bevy version

Bevy 0.11

What you did

I'm working on a PR to update leafwing-input-manager: Leafwing-Studios/leafwing-input-manager#364

What went wrong

Leafwing input manager has a struct ActionState that takes a generic that is used on a #[reflect(ignore)] PhantomData field:

#[derive(Resource, Component, Clone, Debug, PartialEq, Serialize, Deserialize, Reflect)]
pub struct ActionState<A: Actionlike> {
    /// The [`ActionData`] of each action
    ///
    /// The position in this vector corresponds to [`Actionlike::index`].
    action_data: Vec<ActionData>,
    #[reflect(ignore)]
    _phantom: PhantomData<A>,
}

We are getting an error when registering this type with bevy saying our generic type must implement TypePath.
This seems potentially limiting to the end users of LWIM and I'm not sure it was intended as it isn't mentioned in migration guides.
Is this restriction something that could be lifted?

Additional info

There's a conversation about this on the LWIM PR starting here:
Leafwing-Studios/leafwing-input-manager#364 (comment)

To try this out, you can checkout the branch for that PR and remove the TypePath requirement I added from this line:
https://github.com/Leafwing-Studios/leafwing-input-manager/blob/7fb55b001a4aa949b1863dd2e0007d9512960625/src/lib.rs#L81

Here's the line and error we are getting:
https://github.com/Leafwing-Studios/leafwing-input-manager/blob/dfbe44b22fae01434737fb498dfb10d5ca20057d/src/plugin.rs#L146

        app.register_type::<ActionState<A>>()
error[E0277]: the trait bound `A: TypePath` is not satisfied
   --> src\plugin.rs:146:29
    |
146 |         app.register_type::<ActionState<A>>()
    |                             ^^^^^^^^^^^^^^ the trait `TypePath` is not implemented for `A`
    |
note: required for `ActionState<A>` to implement `GetTypeRegistration`
   --> src\action_state.rs:85:80
    |
85  | #[derive(Resource, Component, Clone, Debug, PartialEq, Serialize, Deserialize, Reflect)]
    |                                                                                ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
86  | pub struct ActionState<A: Actionlike> {
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `App::register_type`
   --> D:\Packages\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_app-0.11.0\src\app.rs:816:29
    |
816 |     pub fn register_type<T: bevy_reflect::GetTypeRegistration>(&mut self) -> &mut Self {
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `App::register_type`
    = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
    |
82  | impl<A: Actionlike + bevy::reflect::TypePath> Plugin for InputManagerPlugin<A> {
    |                    +++++++++++++++++++++++++

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions