S&box Wiki

Revision Difference

Networked_Types#562929

<cat>Code.Network</cat> <title>Networked Types</title> ⤶ <note>Page needs to be entirely rewritten for the scene system, lets wait until networking is more finalized though.</note>⤶ # 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](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types) will work |⤶ | Vector2, Vector3, Rotation, Angles, Transform | Supported |⤶ | GameObject | Supported |⤶ | Component | Supported |⤶ | GameResource | Supported |