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.

Bytes4096

An array of bytes with an upper limit of 4094 bytes (2 bytes reserved for length).

Currently we do not support automatic packet fragmentation and so packets bigger than the internal MTU (~1200 bytes) may be never sent.

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 replicated fields for baked MonoBehaviours.

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.

Commands

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

Here's a simple example Command:

command Damage [routing "AuthorityOnly"]
  amount Int
  explosive Bool

Routing defines to whom the command can be sent. Currently two values are supported:

  • AuthorityOnly - command will be received only by the owner of the target entity

  • All - command will be received by every client that has a copy of this entity

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