Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question I have a question about entity design

Discussion in 'Entity Component System' started by ops0606, Sep 29, 2023.

  1. ops0606

    ops0606

    Joined:
    Dec 6, 2016
    Posts:
    6
    As a project progresses, I believe that a single entity can have multiple components to meet various requirements. However, this would reduce the number of entities placed within a single chunk, and wouldn't this gradually decrease the cache hit efficiency of very basic systems (like systems related to transforms)? In such cases, is it recommended to separate components related to a specific topic into separate entities and set parent-child relationships?

    ps. I translated it with chatGPT. Thank you for reading!
     
  2. UniqueCode

    UniqueCode

    Joined:
    Oct 20, 2015
    Posts:
    40
    The simple answer is: don't think about it.
    Think about optimization once it becomes relevant.

    The worst case would be to have a unique archetype for every single entity. This would obviously waste a lot of memory. The Ecs tradeoffs would basically be wrong for you in this case. It's strength in numbers.
    But having a few almost empty chunks is still a better memory layout than OOP by a huge margin.
    Ah, afaik a cacheline is a few bytes, so Ecs accessing one or two entites does waste a bit of memory but will not fill the cache because most of it is never accessed.

    Hope that was helpful.
     
    apkdev likes this.