Skip to content

Generated entity data

EntitySet and the contracts generated code is written against — the typed way into a project's entities, and the seal a lookup depends on.

All documentation — Reference
On this page

Everything on this page is what generated code is built out of. You call into it; you do not implement it.

EntitySet

EntitySet<T> is every entity of one definition, indexed by code and by id and enumerable in a stable order. Read-only once loaded, and it implements IReadOnlyList<T>.

Member
T this[string code]Throws EntityNotFoundException when nothing has that code
bool TryGet(string code, out T entity)
T? Find(string code)
bool Contains(string code)
T? ById(string id)
IReadOnlyList<T> Resolve(IEnumerable<string>? ids)
IReadOnlyList<T> WithTag(string tagId)In the set’s own order
Count · this[int index] · GetEnumerator()The list surface

ById is the shape anything crossing the engine boundary needs: a step’s references, a save’s state and the payload all carry ids. this[code] is the shape your code and the generated constants use.

Resolve turns a reference field’s ids into entities, in order. An id that resolves to nothing is dropped rather than kept as a hole, matching how the engine treats a reference it cannot look up — so the result can be shorter than the input.

WithTag takes a tag id, because a tag has no stable code.

EntityNotFoundException

Derives from KeyNotFoundException, so an existing catch around a dictionary lookup still works. It names the code and the definition in its message — Definition and Key are both on it.

IProjectEntity

The minimum an entity must be for a set to index it: an Id that survives a rename, and the author’s own Code, which is what an expression names the entity by. Implemented by the generated entity base class.

ITaggedEntity is its companion — the tag ids on an entity — and it is what WithTag asks. The generated base implements it, so a project with no tags still compiles.

EntitySets

Install<T> and Seal<T>: the two operations the generated loader needs.

The generated state contracts

IGameState composes four subsystems, and GameState is the default composition the generated bootstrapper constructs.

IVariableStore VariablesRead and write a variable by its code
IEntityStore EntitiesRead and write an entity field, by entity code and field name
ICommandDispatcher CommandsDispatch a command by code with typed arguments
IEnumRegistry EnumsEnum and bitmask lookups — the option code for a value, and back

Both IVariableStore and IEntityStore also answer the enum type code for a field, which is what lets the evaluator resolve an enum comparison rather than comparing two bare numbers.

Written for
Unity developers · Advanced integrators
Last updated