Hi, my character has multiple stats(HP, moveSpeed,…), it could be to 40-60 stats, very much.
At traditional way, my Character has a List. Each StatComponent has differerent Key.
I want to make entity has multiple stats like that.
But when i add mutilple StatComponent to my Entity. On Entity Inspector only show the last one.
So my question is my current way is wrong ? What is the best solution for this case ?
I don’t see any documentation about add duplicated component , but I think the mechanism of it is that when I add duplicated, it will override the existing one.
This is my component i add for my entity
public struct StatComponent : IComponentData
{
public StatType Key;
public float Value;
}
The trivial way is to use IBufferElementData instead of IComponentData, so instead of single component you will add DynamicBuffer<StatComponent> to entity. Like entityManager.AddBuffer(entity).Add(statA). This way you can have dynamic count of same struct assigned to entity. Search key timing isn’t best in this way though.
So more efficient way is to implement custom data structure container such as hash based collection for faster search.