#DOTS Game State

1 messages · Page 1 of 1 (latest)

slow fable
#

How would you manage game states in DOTS?

I saw an old post mentioning you have to spawn / despawn components to manage game states, is that still the same in recent DOTS?
Sounds pretty weird of handling game states having to spawn entities to manage the states.

For example in Bevy ECS you can just define an enum and then the user can choose whether to run the system if it is in the Playing game state based on an enum that is globally accessible and is not an entity but rather a global "resource". But from what I read using an enum to manage game states in DOTS is not viable since there is going to be a performance cost because systems would always run and having to check what state it currently is each update.

Reference

https://bevy-cheatbook.github.io/programming/states.html

open spire
#

if you want a similar solution you could create tag components for the different states (i.e. components with no data) and then have a master system somewhere that manages an entity and adds/removes those components on that entity

struct GameState_Playing : IComponentData {}

then in your other systems' OnCreate you can say RequireForUpdate<GameState_Playing>(), and the systems will only update when that game state is present

#

unity's ecs will internally do an efficient check to see whether the component exists on any entity in the world before invoking OnUpdate

#

of course it's not as clean as having the states encapsulated within an enum, but in practice it should suffice for most use cases

#

(so in other words there's no change to this in recent ecs)

raw pivot
#

I suppose that technically speaking you could also enable/disable systems or system groups?

I haven't tried this in unity's ECS, but this is how we implemented pause functionality in Quantum's ECS

Personally I don't think it's very strange to use data to represent game state though

open spire
#

you could do that yes, though then you'd need the game state manager to be somehow aware of all systems and system groups that need to be enabled/disabled

slow fable