menu_bookDocumentation
[Sync] Attribute: SyncFlags.FromHost, SyncFlags.Interpolate, SyncFlags.Query — How Property Sync Works
[Sync] Attribute: SyncFlags and How Property Synchronization Works
The [Sync] attribute marks a component property for automatic network synchronization from the owner to all other clients. The engine's source generator wraps the property getter and setter with sync_GetValue and sync_SetValue at compile time.
SyncFlags
CSHARP
[Flags]
public enum SyncFlags : uint
{
FromHost = 1, // Host controls this value, not the owner
Query = 2, // Poll the getter each tick instead of relying on the setter being called
Interpolate = 4 // Interpolate between ticks (float, double, Angles, Rotation, Transform, Vector3 only)
}Usage
CSHARP
// Basic sync — owner sends to everyone
[Sync] public float Health { get; set; }
// Host-controlled sync (replaces obsolete [HostSync])
[Sync( SyncFlags.FromHost )] public int Score { get; set; }
// Interpolated sync — smooth movement on proxies
[Sync( SyncFlags.Interpolate )] public Vector3 Velocity { get; set; }
// Query mode — value is polled each tick (use when getter can change without setter being called)
[Sync( SyncFlags.Query )] public float SomeComputedValue { get; set; }
// Combined flags
[Sync( SyncFlags.FromHost | SyncFlags.Interpolate )] public Vector3 HostPosition { get; set; }How It Works Internally
- The source generator wraps the setter with _syncSetValue. On set, it finds the network root, looks up the property's slot in the NetworkObject.dataTable, and updates the slot hash.
- If the local client does not have control of the slot (i.e., they are a proxy), the setter is a no-op unless NetworkTable.IsReadingChanges is true (i.e., the value is being applied from a network snapshot).
- With SyncFlags.Interpolate, the getter returns an interpolated value from InterpolatedSyncVar<T> on proxy clients. Supported types: float, double, Angles, Rotation, Transform, Vector3.
- [HostSync] is obsolete — use [Sync( SyncFlags.FromHost )] instead.
- SyncFlags.Query (formerly [Sync( Query = true )]) is for properties whose value can change without the setter being called (e.g., computed properties).
Important: Sync Only Works on Networked Objects
[Sync] properties only synchronize when the GameObject has been spawned on the network (NetworkMode.Object). On non-networked objects, the setter just sets the backing field normally.
Was this helpful?