Skip to content

component discovery#7256

Closed
robtfm wants to merge 1 commit intobevyengine:mainfrom
robtfm:component_discovery
Closed

component discovery#7256
robtfm wants to merge 1 commit intobevyengine:mainfrom
robtfm:component_discovery

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-Needs-SME This type of work requires an SME to approve it. 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-Needs-SME This type of work requires an SME to approve it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants