terminalCode Example

Sync Properties for Networked State

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Sync Properties for Multiplayer

The [Sync] attribute automatically synchronizes property values to all clients when they change.

Basic Sync

CSHARP
public sealed class HealthComponent : Component
{
    // Automatically synced to all clients
    [Sync] 
    public float Health { get; set; } = 100f;
    
    [Sync]
    public bool IsDead { get; set; }
}

Sync Flags

Customize sync behavior with SyncFlags:

CSHARP
// Host-authoritative - only host can change
[Sync(SyncFlags.FromHost)]
public float GameTime { get; set; }

// Interpolated - smooth value changes over ticks
[Sync(SyncFlags.Interpolate)]
public Vector3 Position { get; set; }

// Combined flags
[Sync(SyncFlags.FromHost | SyncFlags.Interpolate)]
public Vector3 PlayerPosition { get; set; }
FlagDescription
SyncFlags.QueryEnables Query Mode for late-joiners
SyncFlags.FromHostOnly host can modify the value
SyncFlags.InterpolateSmoothly interpolate value changes

Important Notes

Health Component Example

CSHARP
public sealed class PlayerHealth : Component
{
    [Sync] 
    public float CurrentHealth { get; private set; } = 100f;
    
    [Sync(SyncFlags.FromHost)]
    public float MaxHealth { get; set; } = 100f;
    
    public void TakeDamage(float damage)
    {
        // If not host, request damage via RPC
        if (!Networking.IsHost)
        {
            RequestDamageRpc(damage);
            return;
        }
        
        CurrentHealth = MathF.Max(0, CurrentHealth - damage);
    }
    
    [Rpc.Broadcast]
    private void RequestDamageRpc(float damage)
    {
        if (Networking.IsHost)
            TakeDamage(damage);
    }
}
Was this helpful?