Search Unity

Where and how to store the collection of dynamic component data globally

Discussion in 'Entity Component System' started by hazarartuner, Nov 22, 2019.

  1. hazarartuner

    hazarartuner

    Joined:
    Oct 22, 2016
    Posts:
    6
    Hi,

    I'm studying to understand and use ECS for a couple of weeks. I've build some basic p.o.c projects till this time. After that I started to think and build a more complex p.o.c project but I'm stuck :D

    My project is a basic kind of Match 3 game, like "Candy Crush". I think It is a good project to test and improve my DOTS skills because it is a good type of data oriented project. The problem I'm stuck with is, I'm not sure where and how to store the collection of the all gem items' component data in my game. I've a grid which consists of random type of gems and each gem has a component called GemComponent that contains the gem type and the grid location.

    I want to find all the GemComponents within the entities and loop through to each of them to find the vertically or horizontally matched components/entities. After that I want to collect the matched entities then I want to replace or update their GemComponents values.

    I've watched lots of DOTS specific videos on Unity's youtube channel and found this video
    It seems useful especially for my problems but unfortunately it didn't totally help me.

    According to that talk, I understand that BlobAssets can be used to share any type of data within the entities, and it is really efficient for performance case. But the problem is, they are not mutable. In my case, all GemComponents have a chance to change, therefore BlobAssets seems not useful. I must be able to mutable the GemComponents.

    The second opportunity I've found maybe to store all of the GemComponents within the BufferElementData component and add this component to all of the gem entities. But I'm not sure if it is the correct approach. My question is, how would you solve this problem, what is the best practice for you? Where would you store these collection of data? When you are creating the GemComponent collection, would you collect the gem components within the each system update phase for each gem component?

    I'm sorry for this long question but I think finding the answers for these questions may be really helpful to most of us to better understand the best practices of global data management with DOTS.

    Thanks :)