🐾PurrNet Docs
RPC

ObserversRpc

ObserversRpc broadcasts a method call from the server to all clients observing the object. Every connected client that can see the object receives the call simultaneously.

Client AServerClient BServer → All observing clients

How it works

The server calls a method marked with [ObserversRpc] and PurrNet distributes the packet to every client currently observing that NetworkIdentity. Observers are determined by the Network Visibility system — by default, all connected clients observe all objects.

Common uses: broadcasting game events (player death, game start), pushing authoritative state after server-side validation, and notifying all clients about world changes.

Attribute parameters

ParameterTypeDefaultDescription
channelChannelChannel.ReliableThe transport channel used for the broadcast.
requireServerboolNetwork RulesWhen true, only the server can call this RPC. Overrides Network Rules for this method.
bufferLastboolfalseWhen true, replays the most recent call to newly connecting observers. Use for state that late joiners must receive, like the current round phase.
runLocallyboolfalseWhen true, the server also executes the method locally when it sends the broadcast.

Basic usage

GameManager.cs
using PurrNet;
using UnityEngine;

public class GameManager : NetworkBehaviour
{
    // Server calls this to tell everyone the game started
    [ObserversRpc(bufferLast: true)]
    public void RpcGameStarted(int countdownSeconds)
    {
        // Runs on ALL connected clients (and server if runLocally)
        UI.ShowCountdown(countdownSeconds);
        AudioManager.PlayStartJingle();
    }

    // Server-side trigger — only callable from server code
    [ObserversRpc(requireServer: true)]
    public void RpcForceRestart()
    {
        SceneManager.LoadScene("MainGame");
    }
}

bufferLast for late joiners

Without bufferLast, a client connecting after an ObserversRpc fires will miss it entirely. With bufferLast: true, PurrNet stores the most recent call and replays it when a new observer joins. This is essential for broadcasting initial game state.

HealthSystem.cs
public class HealthSystem : NetworkBehaviour
{
    private int _currentHealth = 100;

    protected override void OnSpawned(bool asServer)
    {
        if (asServer) RpcInitHealth(_currentHealth);
    }

    // bufferLast: new clients joining mid-game immediately get current health
    [ObserversRpc(Channel.Reliable, bufferLast: true)]
    private void RpcInitHealth(int health)
    {
        _currentHealth = health;
        healthBar.SetValue(health);
    }

    public void TakeDamage(int amount)
    {
        if (!isServer) return;
        _currentHealth -= amount;
        RpcUpdateHealth(_currentHealth); // broadcast to all
    }

    [ObserversRpc]
    private void RpcUpdateHealth(int health)
    {
        _currentHealth = health;
        healthBar.SetValue(health);
        if (health <= 0) OnDeath();
    }
}

bufferLast vs SyncVar

For values that change continuously (health, score, position), use SyncVar — it handles buffering automatically. Use bufferLast on ObserversRpc for one-time events that must be replayed (game start, round end).

Situational example — kill feed

KillFeedManager.cs
public class KillFeedManager : NetworkBehaviour
{
    // Server calls this after confirming a kill
    [ServerRpc(requireOwnership: false)]
    public void CmdReportKill(string killerName, string victimName, string weapon, RPCInfo info = default)
    {
        if (!info.asServer) return; // runLocally guard
        // Validate: did info.sender actually make this kill?
        BroadcastKill(killerName, victimName, weapon);
    }

    [ObserversRpc(runLocally: true)]
    private void BroadcastKill(string killer, string victim, string weapon)
    {
        KillFeed.AddEntry(killer, victim, weapon);
    }
}

requireServer

If requireServer is false (default), a client can call ObserversRpc directly if Network Rules allow it. In server-authoritative games, always set requireServer: true or rely on Network Rules to block this.