Search Unity

What is the use case for SystemStateComponentData?

Discussion in 'Entity Component System' started by Deleted User, Jul 13, 2019.

  1. Deleted User

    Deleted User

    Guest

    Why someone should define fields in SystemStateComponentData instead of directly defining them in the system class?
    Is there a performance difference?
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    SystemStateComponentData won't get destroyed when destroying entities. (explicit removement is required) So it can be used to lets say manage internal system states like lists and so one.
     
    florianhanke likes this.
  3. Deleted User

    Deleted User

    Guest

    But you can declare a field in the system and have your data on that field. Then you don't need to be worried about entities getting destroyed.
     
  4. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    No that is not the point.

    Short example:
    You have a system that has an internal list of referenced entities. To manage this list, you need to know when an entity gets added or destroyed to add or remove it from that list. And the easiest way to do that is to use SystemStateComponentData. If an entity is created that needs to be added to that list, you can declare an query of:
    Entities.Without<MySystemComponent>().ForEach(SomeComponent...)

    and if an entity is destroyed you can declare an query like this:
    Entities.Without<SomeComponent>().ForEach(MySystemComponent...)
     
    Deleted User likes this.