How do I have global state variables?

I used to use a ScriptableObject which had some global state variables, such as IsBossActive, for when a boss is active.

I realize this isn’t very ECS-friendly, so what’s the alternative?

I’m thinking of having a game state component which would hold that variable, and when a boss activates, just do an Entities.ForEach to change that variable for every entity that has it. Does this make sense?

I also know of ISharedComponentData, but from what I can tell, you can’t access those types of components in a job if they are altered outside of it (in a GameObject or similar).

There is Singleton Entities for such EntitiesWorld Global data
Or BlobAssetRef for Info that considered static for runtime

1 Like

I would not over complicate things. If you have a single ‘Object’ the performance gain of ECS won’t be noticeable. Just store the data in a scriptable object, a static field, a system field, a persistent NativeHashMap or anything that works for you.

If you have 1000 bosses and you want to do something with all active bosses, than give these entities a IsActiveBossTag component and use it to filter in the system.

1 Like