Can I rely on the index staying the same for lots of separate entities?

I’m wondering if this is true. I’m creating roughly 6 entity’s all at the the same time. The structure is like one main entity and five sub entity’s. I don’t have anything connecting them except for a int component that contains a unique ID.

So then surely if I create 100 * 6 all at the same time in the same order. If I get index 50 of one these entity’s then that will correlate with the other entity’s that were created at the same time?

So basically as long as I don’t change anything structural wise the native arrays should all stay in the same order the entity’s were created in is that correct.

If you are creating this ID why should it change? If you mean Entity.Index then I don’t know if it will suffice. I’m using whole Entity fields and it’s preserved until destroyed.

The ID won’t change. I’m just using that as an example. Say I search for one of those entity types and find the one with the correct ID, then I should be able to use the index of that one to find the other five entity’s that were created at the same time surely.

Indices of new entities aren’t guaranteed to be monotonically increasing. They get recycled.

1 Like

So as long as I don’t create new or remove any of these entities then they should remain the same order? I should note I’m not actually using the index property of the Entity’s because the numbers are all wrong on that anyway. I’m just using index of the nativeararys. I’m just hoping Unity doesn’t jumble the entities or do weird things with them or something for no reason.

I don’t understand what you are asking anymore. It sounds like you are asking about custom indices based on some generation algorithm and whether or not that will be deterministic, of which the answer depends on if your code up to that point is deterministic enough.

1 Like

Sorry, if I wasn’t being clear enough but yeah thats it basically. Anway I’ve created a temporary debug component, that will warn me if the index’s are different, I’ve learned never to trust or take things at face value when programming.