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

SyncEvent

PreviousSyncDictionaryNextSyncHashset

Last updated 5 months ago

Synchronized Event, or most commonly referred as "SyncEvent" are easily definable in your code, and will handle automatically calling events to all listening to the event.

Working with SyncEvent is as easy as using a regular UnityEvent, only having to be mindful of who has authority.

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

//Creates an instance of the event - True means that it is owner authority
[SerializeField] private SyncEvent<int> syncEvent = new(true);

protected override void OnSpawned()
{
    //Listening to the event
    syncEvent.AddListener(SyncEventTest);
}

private void SyncEventTest(int myValue)
{
    //Everyone subscribed to the syncEvent will receive this value when the owner invokes it
    Debug.Log($"Received value: {myValue} from SyncEvent");
}

public void InvokeSyncEvent()
{
    //Because the event is owner auth, only the owner can call the event.
    if (!isOwner)
        return;
    
    //Invoking the event as the owner with the value 10
    syncEvent.Invoke(10);
}

The SyncEvent is serializable in the Unity editor as a Unity Event, meaning that you can easily add events straight from the inspector view.

🖥️
players