S&box Wiki

Networked Types

Networked Types

Any property on a Component can be Networked using the [Sync] or [HostSync] attribute.

Utilizing [Sync] attribute

Adding a [Sync] attribute will network its value. This value will be sent to all Connections/Clients when it changes.

[Sync] public float Health {get; set;} = 100f;

Utilizing [HostSync] attribute

Alternatively, the [HostSync] attribute can be used this behaves the same as the [Sync] attribute. However, the value of the property can only be changed by the Host.

Both of these attributes can be used in conjunction to allow the property value to be changed by both the Host and the Owner of the object.

[HostSync, Sync] public float Health {get; set;} = 100f;

Supported Types

Type Name Support
float, int, bool, byte, long, short, string Any built-in value type will work
Vector2, Vector3, Rotation, Angles, Transform Supported
GameObject Supported
Component Supported
GameResource Supported