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

[API Question] Best way to reference an ISharedComponentData?

Discussion in 'Entity Component System' started by Mr-Mechanical, Nov 26, 2018.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Hello.

    I am iterating over SharedComponentDatas and choosing a subset of them for iteration in another system. What's the best way to store a reference of each SharedComponentData? I am thinking of storing the index of each shared component in the subset for iteration in the next system. What do you guys think is the best approach?

    Thanks.
     
  2. dartriminis

    dartriminis

    Joined:
    Feb 3, 2017
    Posts:
    157
    I usually just use the shared component itself, that way I can easily use it with ComponentGroup.SetFilter(). Although, my shared components are fairly small, so I don't have much overhead when moving them around in memory.

    I've also used entities as shared components (e.g. the entity value is the shared component, and the entity has the data). This worked well for me, because I can easily read/write the shared data in jobs using ComponentData/BufferFromEntity. I can also use EntityArchetypeQueries to query what is essentially the shared component data.
     
    Mr-Mechanical likes this.