Network State

Network Property

A Network Property is a C# property which is replicated across the network. For a property to be networked, the Attribute [Networked] must be added to it. An example of a networked property:

[Networked]
public int Health {get; set;}

Supported C# Types

  1. Int/UInt

  2. Float

  3. Bool

  4. String

  5. Enums

  6. Byte

  7. Long/ULong

  8. Double

Supported Unity Types:

  1. Vector2

  2. Vector3

  3. Quaternion

  4. Color

Network Arrays

Network arrays are just like regular C# arrays, but their syntax is a bit different. They are defined using the NetworkArray generic class.

Example of a network array:

[Networked (size: 10)] public NetworkArray Items { get; set; }

Custom Networked Structs

You can define custom structs that can be networked/replicated by adding the attribute [Networked] to them, like this:

[Networked]
public struct Inventory
{
    public int Item1;
    public int Item2;
}

Important notes:

1. It’s important to make sure that a single struct doesn’t exceed the maximum property size, which is 50 bytes. 2. Structs must not include other user-defined networked structs, only C#’s and Unity’s primitive types. 3. You might want to override/implement equality for the struct for better performance.

Last updated

Was this helpful?