Specification

Primitive Types

These are the primitive types supported in a coherence schema:

Int

Uses a default range of -9999 to 9999.

Float

Uses a default scale of +/- 2400, which is encoded using 24 bits.

Bool

Encoded using a single bit.

Vector2

Encoded using two floats.

Vector3

Encoded using three floats.

Quaternion

String64

The size of a string depends on its length. Try to keep the length of your strings as short as possible, or they won't fit inside a network package.

Entity

The Entity type is used to keep references to other Entities. Technically the reference is stored as a local index that has to be resolved to an actual Entity before usage. Also, since a client might not know about the referenced Entity (due to it being outside of its live query) an Entity reference might be impossible to resolve in some circumstances. Your client code will have to take this into account and be programmed in a defensive way that handles missing Entities gracefully.

Field Settings

Several of the primitive types can be configured to take up less space when sent over the network, see field settings.

Components

The most common definition in schemas is components, which correspond to ECS components in DOTS/ECS and to MonoBehaviours in regular Unity code.

The definition takes a name of the component, and on the following lines an indented list of member variables, each one followed by their primitive type (see above.) The indentation has to be exactly 2 spaces. Here's how it might look:

component Portal
  locked Bool
  connectedTo Entity
  size Float

After code generation, this will give access to a component with the name Portal that has the members locked, connectedTo, and size.

Optionally, each member/type pair can have additional meta data listed on the same line, using the following syntax:

[key1 "value1", key2 "value", etc...]

This is how it might look in an actual example:

component Portal
  locked Bool 
  connectedTo Entity [prio "high"]
  size Float [prio "low", bits "16"]

Built-in components

There are some components that are built into the Protocol Code Generator and that you will always have access to.

Archetypes

Archetypes are used to optimize the sending of data from the server to each client, lowering the precision or even turning off whole components based on the distance from the live query to a particular Entity. Read more about how to define them in the schema on the page Archetypes and LOD-ing.

Events

Events are defined very similarly to components, but they use the event keyword instead.

Here's a simple example Event:

event Sparkles
  lifetime Float

Commands

Commands are defined very similarly to components, but they use the command keyword instead.

Here's a simple example Command:

command Damage
  amount Int
  explosive Bool

When using reflection, there are limitations to what types are supported in commands. See the Supported types in commands section for more information.

Last updated