PurrNet
  • 🐈Introduction
    • ‼️Unique to PurrNet
    • 💲Pricing
    • 💻Compatibility
    • 📚Addon library
    • 🗺️Roadmap
    • 🏎️Performance
      • RPC Benchmarks
      • Network Transform benchmarks
    • 🥰Support PurrNet
  • 🏁Getting Started
    • Installation
    • Minimal Setup
    • Converting to PurrNet
      • Converting from Mirror
      • Converting from FishNet
  • 📚Simple Guides
    • Easy Multiplayer Physics (input Sync)
  • 🖥️Systems and modules
    • Network Manager
      • Network Rules
      • Network Prefabs
      • Network Visibility
        • Distance condition
      • Authentication
    • Transports
      • Composite Transport
      • UDP Transport
      • Web Transport
      • Local Transport
      • Steam Transport
      • Purr Transport
      • Simulating latency
    • Network Identity
      • Ownership
      • Spawning & Despawning
      • NetworkBehaviour
      • Don't destroy on load
    • Network Modules
      • Common Pitfalls
      • Sync Types
        • SyncVar
        • SyncList
        • SyncArray
        • SyncQueue
        • SyncDictionary
        • SyncEvent
        • SyncHashset
        • SyncTimer
        • SyncInput
    • Remote Procedure Calls
      • Generic RPC
      • Static RPC
      • Awaitable RPC
      • Direct Local Execution of RPCs
    • Broadcasts
    • Scene Management
    • Client Side Prediction
      • Overview
      • Predicted Identities
      • Predicted Hierarchy
      • Best Practices
      • Input Handling
      • State Handling
    • Instance Handler
    • Collider Rollback
    • BitPacker
      • Networking custom classes, structs & types
  • Plug n' play components
    • Network Transform
    • Network Animator
    • Network Ownership Toggle
    • Network Reflection
    • Network State Machine
  • 🎮Full game guides
    • 🔫First Person Shooter
    • 🪓Survival Game
  • ✊Community Guides
    • Chat system with broadcasts
  • 🧩Addons
    • Lobby System
  • 🤓Terminology
    • Early Access
    • Channels
    • Client Auth/Everyone (Unsafe)
    • Host
    • Server Auth (Safe)
    • PlayerID
  • 💡Integrations
    • Dissonance
    • Cozy Weather
Powered by GitBook
On this page
  1. Systems and modules
  2. Network Modules
  3. Sync Types

SyncVar

PreviousSync TypesNextSyncList

Last updated 1 month ago

Synchronized variables, or most commonly referred as "SyncVar" are easily definable in your code, and will handle automatically align a script variable between all .

SyncVars are built with the Network Module setup, meaning that you have to initialize it. Below is a usage example:

private SyncVar<int> mySync = new(2); //Now defaults to 2
private SyncVar<int> myOtherSync = new(5, ownerAuth:true); //Defaults to 5, and is owner auth

protected override void OnSpawned(bool asServer)
{
    mySync.onChanged += OnMySyncChange;

    if (asServer)
        mySync.value = 420;

    if (isOwner)
        myOtherSync.value = 69;
}

private void OnMySyncChange(int newValue)
{
    Debug.Log("SyncVar has changed to: " + newValue);
}

When populating the SyncVar, you can do a few things:

  • Feed it nothing: new();

  • Feed it a default: new(5); //In case of number

  • Feed it settings like ownerAuth or sendIntervalInSeconds

🖥️
players