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

Entities referencing #143

Closed
mrazorvin opened this issue Jan 16, 2022 · 2 comments
Closed

Entities referencing #143

mrazorvin opened this issue Jan 16, 2022 · 2 comments

Comments

@mrazorvin
Copy link

mrazorvin commented Jan 16, 2022

Is there a way (or plans) to implement one to many weak references between entities, in ideally world I just want to tell that some entity belongs to another one, so I can query specific components from related entities

Pseudo code

world.ref(EntityID1, (EntityID2, EntityID3));
...
ComponentsView.filter_by_ref(EntityID1).for_each(|component|{
  // component from EntityID2 or EntityID3 if they exists
}) ;

Preamble:
I tried to implement attributes system in my game (int, str, dex, hp, mana etc...)

The problem: Every entity can have only one component of type, but I need to have multiple attribute of same type (since they come from different sources). So I can't use components.

This means that I need to implement attributes as separate entities. Since every unit in my game will have more than 5 attributes, I can't simple iterate over all attributes and find which one relate to main hero when I want to calculate something.

I red part about parent-child relation, but I don't want to add parent component for each attribute, and create parent child hierarchy for each component type

Is there a way or plans to implement one to many weak references between entities

@leudz
Copy link
Owner

leudz commented Jan 16, 2022

No there is no plan for something like this at the moment.
Obligatory link to bevy's relations, an automated way to have entities reference other entities allowing all kinds of patterns.

I red part about parent-child relation, but I don't want to add parent component for each attribute, and create parent child hierarchy for each component type

Why not? You might be able to use or adapt @dakom's hierarchy crate.

At work we use an "indexing pattern".
You'd have an attribute hierarchy (or re-use an already existing hierarchy maybe?). When the hierarchy or BonusAttribute changes you update the Attribute component using all BonusAttribute affecting it.

struct BonusAttribute {
    int: u32,
    str: u32,
    dex: u32,
    hp: u32,
    mana: u32,
    ... 
}

struct Attribute {
    int: u32,
    str: u32,
    dex: u32,
    hp: u32,
    mana: u32,
    ... 
}

@mrazorvin
Copy link
Author

indexing pattern sounds good, I will try to implement attributes with hierarchy and see if I like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants