Skip to content

ExclusiveGroups to handle the Singleton Entity case

Sebastiano Mandalà edited this page May 5, 2019 · 2 revisions

When Svelto.ECS is used to implement the entire application, is not rare to stumble upon the one entity logic scenario. Since we strive to use entity structs instead than entity view structs and implementors, we should compose our entity reusing abstracted entity structs.

In the case of a cursor, we could need to store the position of this cursor, but we shouldn't really use a PositionCursor entity struct, if we already have a more abstracted Position entity struct.

However when it's time to write the engine for the cursor, we can't surely iterate over all the positions used basically in most of the entities in the project, so how to solve this?

Groups come to the rescue again, as the entity will be built in the Cursor group, so that we can query the only position that we can find in the Cursor group.

The use of the QueryUniqueEntity method will also communicate to the other coders your intention to have just one unique entity in that specific group.

You can’t perform that action at this time.