Search Unity

Question Reusing Entities with the same Archetype

Discussion in 'Entity Component System' started by Hiyazcool, Jan 20, 2023.

  1. Hiyazcool

    Hiyazcool

    Joined:
    Sep 19, 2022
    Posts:
    2
    Is it worth reusing entities with rapidly created and destroyed Archetypes, like projectiles, and at which volume of entities would reusing them be less effective?
    Also, how would someone do this while implementing ECS and the rest of the DOTS stack?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    I suppose it depends.
    Recreating new entity guarantees reset state. If you want to reuse entity, then you need also handle reseting the state.

    In some cases that may mean, you need nearly to duplicate the creation system.
    Whichay be not worth it.

    Also, if you got children entities, then you need to manage their state too.

    Plus you need to manage pooling mechanism. Which may potentially overweight the cost of the creation system in some cases.

    All depends on type of the design approach.
     
    Hiyazcool and apkdev like this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    In case of full pure entities - its not worth it.
    Overhead of pooling would be greater than creating entity + setting up data.

    Memory management for Entities is better than you'd think.
    So I'd suggest - don't bother unless its actually a problem.

    In case of hybrid, then yes, you'd want to keep heap objects alive and re-use them.
    But at the same time entity creation part should be handled by the ECS on its own, same case as with pure entities. And heap object should be attached at data "authoring" stage. Basically ECS should not know about pooling system, and vise versa.

    If you want to keep [at least one] archetype allocated, you could always keep one entity to "prewarm" it.
    Although, in most cases its not worth extra complexity. Always profile first.
     
    Last edited: Jan 20, 2023
    Jonas_DM_, Hiyazcool and apkdev like this.