I'm currently building a prototype using only ECS where it's possible.
To share State between systems without creating dependencies I found 2 main ways so far.
The first one :
Have a ComponentData as a singleton in the system,
querying it with
SystemAPI.GetSingleton<T>()
// or SystemAPI.GetSingletonRW<>() if I need to modify stuff in the component in a system update look
and then doing stuff on it.
The second is to do a
EntityManager.AddComponent<T>(SystemHandle);
In the system that do the calculation , then
EntityManager.SetComponentData(SystemHandle, new T(){});
When I calculate the value
Then in the systems that use that component do a :
SystemHandle sytemHandle = EntityManager.World.GetExistingSystem<T>();
To store the reference of the system & then later query :
EntityManager.GetComponentData<T>(sytemHandle)
To request the data.
Thinking long term , code cleanyness etc ... which option seems the most reasonable ?
Both are possible but I don't get when to use what approach.