Skip to content

Allow required components to specify relationships #19751

Open
@Freyja-moth

Description

@Freyja-moth

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

As mentioned in #19045 and #16840 it would be nice to have a way to specify relationships in required components

What solution would you like?

Perhaps something like this?

#[derive(Component)]
#[require(
    Related::<Children>((
        Text::new("Some interesting..."),
        (
            Text::new("writing here."), 
            TextColor(css::PURPLE)
        )
    ))
    // Not sure if this should override or add to the parent if it already exists, leaning to add, but depends on feasibility and what other people want
    Related::<ChildOf>(
        Node
    )
    Related::<Observer>((
        // This gets more tricky because observers are m-m, not sure how to do this without duplicating a lot of observers that do the exact same thing.
    ))
)]
pub struct TextContainer;

What alternative(s) have you considered?

Use the old method, but that doesn't hold up relationship invariants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleS-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