Skip to content
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

Debugging failed IntoSystem macro #16

Closed
alice-i-cecile opened this issue Feb 25, 2021 · 7 comments · Fixed by #17
Closed

Debugging failed IntoSystem macro #16

alice-i-cecile opened this issue Feb 25, 2021 · 7 comments · Fixed by #17

Comments

@alice-i-cecile
Copy link

Stopgap solution for: bevyengine/bevy#1519

IMO, the correct choice here is to have a page for "I can't add my function as a system!" or something of the like. It should explain each of the options that impl SystemParam, and call out common mistakes for each. As an example, missing &mut for Commands, missing & for components etc.

@inodentry
Copy link
Contributor

Would you be willing to help me with collecting examples of error messages to showcase?

each of the options

Could you help me make a list?

@alice-i-cecile
Copy link
Author

Yep, let me dig through the spaghetti that is SystemParam.

  1. Query and QuerySet
  2. QueryFilters
  3. Commands
  4. Res, ResMut and Local (and ChangedRes, but that's probably getting cut)

There should be a few more in 0.5: EventReader and Archetypes (and friends, coming in The PR).

@inodentry
Copy link
Contributor

inodentry commented Feb 25, 2021

I dug through it myself and managed to make a comprehensive list.

I am basically done with the page, I'll make a PR (rather than pushing directly) so that you can give feedback.

But first:

Could you provide a good representative example of what the "arcane compiler error" looks like?

I want to include it as a snippet so that people can know what this page refers to.

I want an example of the compiler error that would be immediately recognizable to anyone encountering the issue.

@inodentry
Copy link
Contributor

Also, what is the maximum supported number of total overall system parameters?

@alice-i-cecile
Copy link
Author

Also, what is the maximum supported number of total overall system parameters?

16

@alice-i-cecile
Copy link
Author

Snippet:

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(malformed_system.system())
        .run();
}

struct Component;
fn malformed_system(query: Query<Component>, mut commands: Commands) {}

This initially results in:

the trait bound `Component: WorldQuery` is not satisfied
the trait `WorldQuery` is not implemented for `Component`

We fix that by adding a &:

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(malformed_system.system())
        .run();
}

struct Component;
fn malformed_system(query: Query<&Component>, mut commands: Commands) {}

which results in:

no method named `system` found for fn item `for<'r, 's> fn(bevy::prelude::Query<'r, &'s Component>, bevy::prelude::Commands) {malformed_system}` in the current scope
`malformed_system` is a function, perhaps you wish to call it

and the final fixed code is:

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(malformed_system.system())
        .run();
}

struct Component;
fn malformed_system(query: Query<&Component>, mut commands: &mut Commands) {}

@inodentry
Copy link
Contributor

Oh! I missed the part about Query<Component> (without the &/&mut) being a common beginner pitfall! Thanks for pointing that out!

Thanks for the snippets, i have all the information i need now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants