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

SyncTimer

The SyncTimer allows for easy synchronizing of a timer automatically counting down.

You can easily do actions such as starting, stopping, pausing and resuming the timer. Most methods accessible should be quite self-explanatory.

The SyncTimer also automatically handles reconciliation of the timer, meaning that it will force align all clients to ensure de-syncing doesn't happen. The more frequent, the more precise it will be, but the more data is used. Generally it is very data light, so don't fear for making the number lower if necessary.

Below is an example usage of the SyncTimer being server authorized (default) and having a reconcile interval of 3 (default)

public TMP_Text timerText;

//false = OwnerAuth
//3 = Reoncile interval
//The reconcile interval deciphers how often it will force align all clients
private SyncTimer timer = new();

private void Awake() 
{
    //onTimerSecondTick is called every 1 second
    timer.onTimerSecondTick += OnTimerSecondTick;
}

protected override void OnSpawned(bool asServer)
{
    //This starts the timer with 30 seconds countdown
    if(isOwner)
        timer.StartTimer(30f);
}

private void OnTimerSecondTick()
{
    //You can also get .remaining to get the precise float value
    //For displaying timers, the remainingInt makes it easy
    timerText.text = timer.remainingInt.ToString();
}

private void PauseGameTimer() 
{
    //Pauses the timer and will sync the remaining time because it's set to true
    timer.PauseTimer(true);
}

private void ResumeGameTimer()
{
    //Will resume the timer from where it was paused
    timer.ResumeTimer();
}
PreviousSyncHashsetNextSyncInput

Last updated 5 months ago

🖥️