Greetings,
While I was tinkering with ECS I realized that I’m relying on ordering from ComponentDataArray extensively.Without this assumed ordering,my systems will fail miserably.Given that my low bug-hunting skills and basic ECS debugging tools I felt the need to clarify it.
Here is an example to show my worries:
There is an entity archetype of “enemy”.EnemyID,HealthData,ManaData and CoinData are components.
I loop through them with IJobParallelFor.
[ReadOnly] public ComponentDataArray<EnemyID> EnemyIDs;
[ReadOnly] public ComponentDataArray<HealthData> HealthDatas;
[ReadOnly] public ComponentDataArray<ManaData> ManaDatas;
[ReadOnly] public ComponentDataArray<CoinData> CoinDatas;
public void Execute(int index) .
{
var enemyID= EnemyIDs[index].ID;
var health=HealthDatas[index].value;
var mana= ManaDatas[index].value;
var coins= CoinDatas[index].value;
}
Normally,if i understood ECS correctly,this should work as entities and their components align correctly in table-like fashion.
Index 0 - Entity 0 - HealthComponent 0 - ManaComponent 0 - CoinComponent 0
Index 1 - Entity 1 - HealthComponent 1 - ManaComponent 1 - CoinComponent 1
Index 2 - Entity 2 - HealthComponent 2 - ManaComponent 2 - CoinComponent 2
But what if I add or remove components on the go,how will ECS responds to that?Let’s assume I removed CoinComponent 1.Can I still use CoinDatas[2] to fetch Entity 2’s CoinComponent?
If not,is there another way to adapt to this other than having an ID value in each component to loop through and find their “parent entity” accordingly?
Thanks in advance.