Singletons
For a component that lives on exactly one entity (game state, camera, player):
csharp
ref var state = ref world.GetSingleton<GameState>(); // throws unless exactly one holder
Entity holder = world.GetSingletonEntity<GameState>();
bool exists = world.HasSingleton<GameState>();A singleton is an ordinary component; there is no separate registration. It exists while exactly one entity holds it:
csharp
world.CreateEntity(new GameState()); // one holder: the singleton exists
world.GetSingleton<GameState>().Score += 10; // ref access, writes go straight to the poolGetSingleton<T>()returns arefto the component and throws unless exactly one entity has it.GetSingletonEntity<T>()returns the holder'sEntity, with the same check.HasSingleton<T>()istrueonly when exactly one entity has the component —falsefor zero and for two or more.
