Skip to content

Allow registering components/resources from ReflectComponent/Resource #15453

@MichalGniadek

Description

@MichalGniadek

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

I would like to be able to get or create a ComponentId with just TypeId (and TypeRegistry) assuming a given type reflects the required trait. This currently can only be done if a given component/resource has already been initialized (with Components::get_id and Components::get_resource_id).

A specific example: a scripting language that wants to check for existance of a resource/component (on an entity) where the resource resource/component is defined in rust.

What solution would you like?

For ReflectComponent:

  • add a new function that takes &mut World and calls world.init_component::<T>()

For ReflectResource:

  • would require adding a new method to World that initializes a resource without inserting
  • add a new function that takes &mut World and calls this new function

What alternative(s) have you considered?

  • Require users to manually register all resources/components they are planning to use first (this is what I'm currently doing)
  • Somehow initialize all registered types that #[reflect(Component, Resource)] automatically when registering a type inside of the type registry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-FeatureA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions