These are the primitive types supported in a coherence schema:
Uses a default range of -9999 to 9999.
Uses a default scale of +/- 2400, which is encoded using 24 bits.
Encoded using a single bit.
Encoded using two floats.
Encoded using three floats.
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.
An array of bytes with an upper limit of 4094 bytes (2 bytes reserverd for length).
Currently we do not support automatic packet fragmentation and so packets bigger than the internal MTU (~1200 bytes) may be never sent.
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.
Several of the primitive types can be configured to take up less space when sent over the network, see field settings.
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:
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:
This is how it might look in an actual example:
There are some components that are built into the Protocol Code Generator and that you will always have access to.
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 are defined very similarly to components, but they use the command
keyword instead.
Here's a simple example Command:
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.