Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Chunk components

Discussion in 'Entity Component System' started by Jay-Pavlina, Jan 20, 2019.

  1. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    I saw that the latest update (0.0.12-preview.23) made it possible to add components to chunks. Does anyone have an example of a use case for this? Also, I thought that chunks change a lot under the hood when you are adding/removing components to entities so I don't know how that would affect chunk components.
     
  2. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    I think in the big city demo they were doing chunk level culling.
    So if you know that all entities within a chunk are positionally static and closely located for example, you might pre-calculate a single world bounds component from all the entities in that chunk. Then you can use that to cull entire chunks from processing.

    - Edit -
    Also as you can find out when a chunk has been invalidated, you can update such data only if and when invalidation occurs.

    - Edit2 -
    Ooh even better, you might be able to use this to share data across individual entities in IJobProcessComponentData. Possibly very useful for parallel jobs in general if you can accumulate data in the chunk then combine them all at the end.
    More possibilities sprout up the more you start thinking about it.
     
    Last edited: Jan 20, 2019
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I think this is one of the thing like hero balance change in game, where it takes time to discover the use and replace the old meta.

    Probably the first step you will need to use the new EntityManager.LockChunk so it does not change. (If it is going to then you would get an exception)

    How it is implemented is that each chunk gains one free innate entity ("meta chunk entity") and you can do anything to it like any entity. From my game, I have a chunk with 5 entities but they all have an important index. Sometimes I want to do something to the one indexed 0 and 5 and I would have to do linear search if not cheating with externally maintained storage/indexed by native array. Now maybe I could add a DynamicBuffer to the meta chunk entity that acts as an indexer then lock the chunk to prevent accident. Then all I need to pass around is ArchetypeChunk I have locked, not even have to query or use CG anymore. Also at anytime I have 1 from all these 5 entities I could ask for its chunk then access this meta entity and jump to others.
     
    Singtaa likes this.
  4. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    That makes sense. I didn't know you could lock the chunk.
    How do you access this entity?
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    From any query by explicitly including ChunkHeader new built-in component and they would come out from hidden. (works like Disabled/Prefab but the component is already attached)
     
    Jay-Pavlina likes this.