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

component discovery #7256

Closed
wants to merge 1 commit into from
Closed

Conversation

robtfm
Copy link
Contributor

@robtfm robtfm commented Jan 17, 2023

Objective

in rendering we are increasingly moving from resources to components attached to the camera entity. each time we do this, we worry about how people (and editors) will find the components.
find a nice way to identify components that can be attached to entities with specific other components.

Solution

add #[derive(PairsWithOthers)] to a component to specify it as a component that likes other things added alongside it. this generates a PairsWithXXX trait that can be linked from the docs for the component. see e.g. Camera3dBundle:

ide_popup

add #[pairs_with(YYY)] to components that want to be on an entity with XXX. this generates an impl of the trait. then the components can be found on the doc page:

pairs_with_camera

  • todo: maybe find a better way to reference the PairsWithXXX trait - currently this uses a string lookup in pairs.rs which would need to be updated for each new PairsWithOthers type. Might not be too bad as there are not many of them.
  • todo: add pairs_with for many other components (suggestions pls).
  • note: this could be a basis for editor functionality as well maybe.

@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR labels Jan 17, 2023
@alice-i-cecile
Copy link
Member

This is related to archetype invariants (#1481, #5121). We should think about how this fits into that cohesively.

@alice-i-cecile alice-i-cecile added the A-Editor Graphical tools to make Bevy games label Jan 17, 2023
@james7132
Copy link
Member

james7132 commented Jan 17, 2023

I can see this being useful in the future, but codegen for the sake of docs seems backwards. Wonder if this could (for now) just generate a #[docs(...) attribute instead and have it forward compatible to generate metadata/code when we have a concrete reason to do so.

@robtfm
Copy link
Contributor Author

robtfm commented Jan 17, 2023

Wonder if this could (for now) just generate a #[docs(...) attribute

do you mean generate a doc attribute on the camera (for example) from the other components?

i did try to #[cfg(doc)] various parts of it to keep codegen down but it seems like when generating docs for a crate, the non-doc-cfg version of imported crates are used as the context for generating docs so that doesn't seem to work.

@alice-i-cecile
Copy link
Member

do you mean generate a doc attribute on the camera (for example) from the other components?

Yeah, that's what I would want. If needed we can probably get an appropriate attribute added upstream too.

@robtfm
Copy link
Contributor Author

robtfm commented Jan 17, 2023

sorry but i've got absolutely no idea how i could do that.

@alice-i-cecile
Copy link
Member

Yeah; I'll ask around for solutions here. Going to close this out, but I'm chewing on this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Editor Graphical tools to make Bevy games C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants