Skip to content

Refactor Component::init_component_hooks to split apart component hook methods #17411

Closed
@alice-i-cecile

Description

@alice-i-cecile

Component's init_component_hooks method is intimidating and a bit frustrating to use. The obvious solution is to simply make each type of component hook its own method.

As @James-o-brien points out, the most naive solution won't work, because we want to cache whether or not each component has each kind of hook (stored in the flags on archetypes). As far as we know, there's no way to statically check if the function provided is actually a no-op.

This came up in the context of relationships.

This feels like a weird place for this method. I'd kinda prefer making on_insert etc methods for Component (and removing the awkward register_component_hooks API), and then generating those methods in the Component trait with the Relationship derive macro.

Originally posted by @alice-i-cecile in #17398 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions