Skip to content

Add a simple method to get a ComponentId for a given Component type #5060

@alice-i-cecile

Description

@alice-i-cecile

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

Being able to extract the ComponentId for a given component of type C is surprisingly unintuitive.

What solution would you like?

Create a public method on Component that mirrors Bundle::component_ids().

EDIT: see below; this isn't the right API. These methods should live on World and Components instead.

What alternative(s) have you considered?

  1. Use world.init_component::<C>(). This is unintuitive, but basically works.
  2. Convert the component type into a bundle, and call (C, )::component_ids(&mut components, &mut storages).iter().next().unwrap(). Which is more than a little cursed.

Additional context

Discovered while working on #1481 with @plof27.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions