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

SyncDictionary

PreviousSyncQueueNextSyncEvent

Last updated 5 months ago

Synchronized Dictionary, or most commonly referred as "SyncDictionary" are easily definable in your code, and will handle automatically align a dictionary between all .

In theory, you could just convert a dictionary to a SyncDictionary, and it should work. Working with it is the exact same with adding, setting, removing or clearing.

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

//Creates a new instance of the dictionary - `true` means it is owner auth. 
[SerializeField] private SyncDictionary<int, float> myDictionary = new(true);

protected override void OnSpawned()
{
    //Subscribing to changes made to the dictionary
    myDictionary.onChanged += OnDictionaryChanged;
}

private void OnDictionaryChanged(SyncDictionaryChange<int, float> change)
{
    //This is called for everyone when the dictionary changes.
    //It will log out the Key, Value and operation
    Debug.Log($"Dictionary updated: {change}");
}

private void ChangeMyDictionary()
{
    //This will change or add a value to the dictionary
    myDictionary[123] = 0.69f;
    
    //This will remove the value from the dictionary
    myDictionary.Remove(123);
    
    //This will clear the dictionary
    myDictionary.Clear();
    
    //This will mark the key as dirty
    myDictionary.SetDirty(123);
}

The SyncDictionary is custom serialized in editor, in order to make visual debugging easier.

🖥️
players