This document is about: FUSION 2-SHARED
SWITCH TO

Networked Properties

Overview

Networked Properties are properties of a NetworkBehaviour derived class that define the networked State of its associated Network Object.

To define a Networked Property, simply add the [Networked] attribute to an auto-property of a NetworkBehaviour derived class.

DO NOT implement these properties yourself - leave them as auto-properties. If you need any special property handling of your own you will need to wrap them in another property.

C#

public class PlayerBehaviour : NetworkBehaviour
{
  [Networked] public float Health { get; set; }
}

Allowed Types

The following types are supported by Fusion and can be [Networked]:

  • Primitives: byte, short, int, long, ushort, uint, ulong, float, double
  • Unity Types: Vector2, Vector3, Vector4, Quaternion, Vector2Int, Vector3Int, Rect, RectInt Color, Color32
  • Fusion Types: NetworkObject, NetworkBehaviour, NetworkString<>, NetworkBool, Angle, NetworkId, PlayerRef, SceneRef, TickTimer
  • Strings (require Capacity Attribute)
  • Structs implementing INetworkStruct

Setting Default Values

It is possible to set default values for [Networked] properties.

Common types

For most common types a simple assignment is sufficient.

C#

public class PlayerBehaviour : NetworkBehaviour
{
  [Networked] public float Health { get; set; } = 100;
  [Networked] public NetworkObject DefaultNetworkObject { get; set; } = GameObject.FindGameObjectWithTag("Foo").GetComponent<NetworkObject>();
}

Collections

Network Collections such as NetworkArray<T> , NetworkDictionary<K, V> , NetworkLinkedList<T> and NetworkString<_size> require a special syntax. Please refer to the page of the same name for more information.

Capacity

The [Capacity] attribute is used to define the maximum size of NetworkArray, NetworkDictionary, NetworkLinkedList, NetworkString and strings.

C#

public class MyNetworkBehaviour : NetworkBehaviour
{
  [Networked, Capacity(14)]
  string MyString { get; set; }

  [Networked, Capacity(8)]
  NetworkArray<byte> MyArray { get; }
}

Change Detection

See Change Detection

Back to top