Why someone should define fields in SystemStateComponentData instead of directly defining them in the system class?
Is there a performance difference?
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.
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.
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().ForEach(SomeComponent…)
and if an entity is destroyed you can declare an query like this:
Entities.Without().ForEach(MySystemComponent…)