Class NetworkSyncOptions
- Namespace
- SteamNetworkLib.Sync
- Assembly
- SteamNetworkLib.dll
Configuration options for HostSyncVar<T> and ClientSyncVar<T> behavior. All properties have sensible defaults for the simplest developer experience.
public class NetworkSyncOptions
- Inheritance
-
NetworkSyncOptions
- Inherited Members
Remarks
This class follows the same pattern as NetworkRules - providing high-level abstractions with sensible defaults while allowing advanced configuration.
// Simple usage with defaults
var score = client.CreateHostSyncVar("Score", 0);
// Advanced usage with custom options
var options = new NetworkSyncOptions
{
KeyPrefix = "MyMod_",
WarnOnIgnoredWrites = true
};
var settings = client.CreateHostSyncVar("Settings", new GameSettings(), options);
Constructors
NetworkSyncOptions()
Creates a new instance with default options.
public NetworkSyncOptions()
Properties
AutoSync
If true, automatically syncs value changes when the value is set. Default: true
public bool AutoSync { get; set; }
Property Value
Remarks
When enabled, setting Value immediately propagates the change to all connected clients.
Disable this if you need to batch multiple changes before syncing manually with Flush().
KeyPrefix
Key prefix to avoid collisions with other mods using SteamNetworkLib. Default: null (no prefix)
public string? KeyPrefix { get; set; }
Property Value
Remarks
Recommended for published mods to prevent key collisions.
The final key will be: {KeyPrefix}{key}
var options = new NetworkSyncOptions { KeyPrefix = "MyMod_" };
var score = client.CreateHostSyncVar("Score", 0, options);
// Actual Steam lobby data key: "MyMod_Score"
MaxSyncsPerSecond
Maximum number of syncs per second. If 0, no rate limiting is applied. Default: 0 (unlimited)
public int MaxSyncsPerSecond { get; set; }
Property Value
Remarks
When set to a value greater than 0, rapid value changes will be throttled to this maximum rate. Useful for high-frequency updates like player positions.
The latest value is always sent when the rate limit expires.
Serializer
Custom serializer for the value type. If null, uses the default JsonSyncSerializer.
public ISyncSerializer? Serializer { get; set; }
Property Value
Remarks
Implement ISyncSerializer for custom serialization logic.
The default JSON serializer supports:
- Primitives: int, float, double, bool, string, long
- Collections: List<T>, Dictionary<string, T>, arrays
- Custom types with parameterless constructor and public properties
SyncOnPlayerJoin
If true, syncs current value to newly joined players. Default: true
public bool SyncOnPlayerJoin { get; set; }
Property Value
Remarks
This ensures late-joining players receive the current state. For HostSyncVar<T>, the host re-broadcasts the value. For ClientSyncVar<T>, each player's value is already available via Steam member data.
ThrowOnValidationError
If true, validation errors throw exceptions. If false, they are logged and invoke OnSyncError. Default: false
public bool ThrowOnValidationError { get; set; }
Property Value
Remarks
When false (default), validation errors are handled gracefully and don't interrupt execution.
When true, validation errors will throw SyncValidationException.
WarnOnIgnoredWrites
If true, logs a warning when a non-host attempts to write to a HostSyncVar<T>. Default: false
public bool WarnOnIgnoredWrites { get; set; }
Property Value
Remarks
Useful for debugging during development to catch accidental writes from non-host clients.
The write is always silently ignored regardless of this setting - this only controls logging.