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

Construct type_name from ComponentId #5104

Closed
alice-i-cecile opened this issue Jun 26, 2022 · 1 comment
Closed

Construct type_name from ComponentId #5104

alice-i-cecile opened this issue Jun 26, 2022 · 1 comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-ECS Entities, components, systems, and events A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

When attempting to debug and display error messages for ComponentId-related code, we can only report the raw ComponentId(usize) to the users. This is not very helpful for debugging purposes.

What solution would you like?

  1. When components are initialized via init_component::<T>, store the type name in Components.
  2. Provide a Components::type_name(component_id: ComponentId) -> Option<String> method.
  3. Allow users to store a custom string when initializing a component manually, to allow users to provide user-friendly types for non-Rust components.

What alternative(s) have you considered?

a) Store the type name as part of ComponentId. This would be extremely convenient, but increases the size of a struct in the hot path of the ECS.
b) Provide a method to get an Option<TypeId> from a ComponentId, then convert that into a type name. Unfortunately, Rust does not provide any tools for the second part of this step: type names can only be constructed from values and types.

Additional context

#1481 needs this to significantly improve error reporting.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types A-Diagnostics Logging, crash handling, error reporting and performance analysis labels Jun 26, 2022
@alice-i-cecile
Copy link
Member Author

alice-i-cecile commented Jun 26, 2022

This is already accessible: see the name field on Components -> ComponentInfo -> ComponentDescriptor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-ECS Entities, components, systems, and events A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

1 participant