Search Unity

Using tag components vs shared component data

Discussion in 'Entity Component System' started by Deleted User, Aug 12, 2019.

  1. Deleted User

    Deleted User

    Guest

    There are two ways (afaik) to mark entities.
    1- Adding an empty component to work as a tag
    2- Adding a shared component data and filtering results.

    For example, If you want to have 3 types of some object (For example food), You can do:

    Code (CSharp):
    1. public struct FoodType1 : IComponantData {}
    2.  
    3. public struct FoodType2 : IComponentData {}
    4.  
    5. public struct FoodType3 : IComponentData {}
    and attach one of these components based on food, or you can do:

    Code (CSharp):
    1. public struct FoodType : ISharedComponentData
    2. {
    3.      public int Type; // You can also use enums
    4. }
    and attach the shared component data to all foods and filter based on Type.

    Can anyone compare these two approaches? Which one performs better?
     
    tarkhon likes this.
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    do you need to do the same things to all food*?
    yes => shared component
    no => different tags

    *: possibly differentiating them by values, e.g. prefab to instantiate or amount of effect it has, but the action itself is the same
     
    RBogdy and Deleted User like this.