Specification

Primitive Types

These are the primitive types supported in a coherence schema:

Int

Uses a default range of -2147483648 to 2147483647 (32 bits).

UInt

Uses the default range of 0 to 4294967295 (32 bits).

Int64

Uses the default range of -9223372036854775808 to 9223372036854775807 (64 bits).

UInt64

Uses the default range of 0 to 18446744073709551615 (64 bits).

Float

Encoded using one of the following compression types: None, Truncated, FixedPoint (defaults to None).

Float64

Higher precision floating point using 64 bits. It does not support compression.

Bool

Encoded using a single bit.

Vector2

Encoded using two floats with a specified compression (defaults to None).

Vector3

Encoded using three floats with a specified compression (defaults to None).

Quaternion

Encoded using three components and a sign bit.

Color

Encoded using four components (RGBA).

String

A string with up to 63 bytes encoded using 6 bits for length.

Bytes

An array of bytes with an upper limit of 511 bytes encoded using 9 bits for length.

Packet fragmentation is not supported yet in this version, 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 LiveQuery) 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 LiveQuery 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 of a 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.

Inputs

Inputs represent a group of values that are snapshotted every frame (or fixed frame). This snapshot is then sent to other clients or a session host, so it can be processed by the same code on both ends, resulting in the same outcome.

Example of an input:

input PlayerInput
  XMov Vector2 [compression "None"]
  YMov Vector2 [compression "None"]
  Jump Bool
  Shoot Bool
  Throttle Float [compression "None"]
  Command String

Last updated