EntityReference

So you have a huge army in front of you... They're all similar somehow, how do you keep them apart?

You already know what an Entity is. However, one thing has not yet been mentioned: the ID of an entity can reappear from time to time. This is called recycling, if an Entity with the ID of ‘25’ is destroyed, one of the next entities will receive its ID. An ID will never appear more than once at the same time, but it can appear more often over time.

So it is possible that you have saved an Entity struct somewhere that originally refers to a dwarf... This is destroyed, you don't realise it and the next time you access it, it's suddenly an elf.

To prevent this and work memory-efficiently at the same time, there is EntityReference for this purpose.

If the original Entity to which the EntityReference points is destroyed, EntityReference.IsAlive()will return false. Even if the ID of the Entity has been recycled. It therefore ensures that we only work with the referenced Entity.

And now you can safely and easily handle references to other entities, great, right?

Last updated