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

SyncList

PreviousSyncVarNextSyncArray

Last updated 5 months ago

A Synchronized List, more commonly referred to as a "SyncList", is easily definable in your code. It will handle automatically aligning the contents of a list between all .

Working with SyncLists is as easy as using a regular list, you have only to be mindful of who has authority over it.

SyncLists 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 list - `true` means it is owner auth. 
[SerializeField] private SyncList<int> myList = new(true);

protected override void OnSpawned()
{
    //Subscribing to changes made to the list
    myList.onChanged += OnListChanged;
}

private void OnListChanged(SyncListChange<int> change)
{
    //This is called for everyone when the list changes.
    //It will log out the value, index and operation
    Debug.Log($"List updated: {change}");
}

private void ChangeMyList()
{
    //This will change or add a value
    myList[0] = 69;
    
    //This will remove the value
    myList.Remove(69);
    
    //This will remove the entry at the given index
    myList.RemoveAt(0);
    
    //This will clear the list
    myList.Clear();
    
    //This will insert a value at the given index
    myList.Insert(1, 420f);
    
    //This will mark the index as dirty
    myList.SetDirty(0);
}

The SyncList is serialized in editor, however, you shouldn't edit it here. This is purely for visual debugging

🖥️
players