Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Replace one property of a component

Open woshiZS opened this issue 3 years ago • 1 comments

Hi,

I am wondering if there is a way to change a property of my component and update the index of that property.

Here's some code

using Entitas;

public sealed class MyComponent : IComponent {
    [EntityIndex]
    public long TeamId{get; set;}
    // other properties
    ......
}

If I just change value of TeamId, the index will not be notified by the group. Instead I need to replace or remove the correspoding componet so that the Index will refreshed. Is there a easier way to notify my index without removing or replacing other properties? Cheers

woshiZS avatar Jul 11 '21 05:07 woshiZS

We've done this in our project. I can't recall how we handled it exactly off the top of my head, and I'm leaving for vacation in the morning.

If you haven't gotten your solution in 1 week, remind me and I'll share our approach.

JustinSchneider avatar Jul 11 '21 06:07 JustinSchneider

@woshiZS when you use entity.ReplaceMyComponent(teamId, other, properties) it should always update the index. This is fine to do and will also reuse the components itself.

You can also consider to have less properties per component, e.g.

public sealed class TeamIdComponent : IComponent {
    [EntityIndex]
    public long Value;
}

btw, you don't need get and set. I would recommend to get rid of those, unless you need them for sth

sschmid avatar Aug 25 '22 21:08 sschmid