Search Unity

Shared Buffer / Arrays between Entities?

Discussion in 'Entity Component System' started by desertGhost_, Aug 19, 2019.

  1. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    Hi,

    What would be the best way to go about sharing a buffer / array between entities?

    I have several systems that need to change component data values on an entity based on thresholds. Currently, I am using a dynamic buffer which is populated by an authoring component and never changes. Each buffer element contains a threshold and data about how to change component values. The system iterates through this dynamic buffer in a burst compiled c# job and selects the buffer element that meets the threshold.

    Functionally this system works as intended, but I have a lot of entities that share the same threshold information that never changes (they have dynamic buffers that are populated with the same exact information) and I would like to share this data in memory if possible.

    Is there a straightforward way to share this information between entities?

    Thanks.
     
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    Look at BlobAssets, BlobAssetReference<T> and BlobArray<T> for data that can be created once, and shared between many entities.
     
  3. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    Thank you. Looking at the BlobArray in the scripting API and I think it will work perfectly for my use case.
     
  4. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
  5. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    Okay, I'll play around with BlobAssets, but I may hold off on adopting them for my use case until they are a bit more developed (I'd like to see them add a NativeArrayFromBlobArray Accessor for jobs or something like that).