Network Rules
NetworkRules is a ScriptableObject that defines the authority model for the entire game — who can spawn objects, call RPCs, and write sync state.
What Are Network Rules?
Every PurrNet project has one active NetworkRules asset assigned on the NetworkManager. Rules answer a single question for every network operation: Is this machine allowed to do this right now?
Rules are checked before an RPC is dispatched, before a spawn is processed, and before a SyncVar write is applied. Violations are silently rejected on the server — no exception on the client — so the game stays stable even if a client attempts something unexpected.
Three Built-In Presets
| Preset | Authority | Common Use |
|---|---|---|
Unsafe | Full client authority — any client can spawn, despawn, and write SyncVars freely. | Rapid prototyping, single-player-with-network, game-jam builds |
ServerOwner | Server + the current owner of an object share authority. | Co-op games, player-owned vehicles, owner-driven inventory |
ServerStrict | Server only — clients request via ServerRpc, server validates and applies. | Competitive multiplayer, authoritative shooters, anti-cheat-critical games |
Creating a NetworkRules Asset
In the Unity Project window, right-click any folder and select Create → PurrNet → Network Rules. Then drag the created asset into the Network Rules field on your NetworkManager component.
Configurable Flags
| Parameter | Type | Default | Description |
|---|---|---|---|
CanClientSpawn | bool | false | Allow connected clients to spawn network objects without requesting from the server. Enabled in the Unsafe preset. |
CanClientDespawn | bool | false | Allow any client to despawn (destroy) networked objects. Only enable with strict ownership validation. |
CanClientSetOwner | bool | false | Allow clients to transfer ownership of objects they don't currently own. Unsafe in competitive games. |
DefaultOwnership | OwnershipMode | Server | Who automatically becomes owner when an object is spawned: Server, Spawner, or None. |
CanCallServerRpc | bool | true | Master switch: allow clients to call [ServerRpc] methods at all. Disabling blocks all client→server RPC calls. |
CanCallObserversRpc | bool | false | Allow clients (not just the server) to broadcast [ObserversRpc] calls. Disabled in ServerOwner and ServerStrict presets. |
CanClientWriteSyncVars | bool | false | Allow clients to write SyncVars that don't have ownerAuth set. Keep false unless prototyping. |
Hot-Swapping Rules at Runtime
You can swap the active rules at any time from server code. Useful for games that change authority models between lobby, gameplay, and post-game phases.
using PurrNet;
using UnityEngine;
public class RulesManager : NetworkBehaviour
{
[SerializeField] private NetworkRules lobbyRules; // ServerOwner
[SerializeField] private NetworkRules gameplayRules; // ServerStrict
[SerializeField] private NetworkRules replayRules; // Unsafe (spectator/replay)
public void TransitionToGameplay()
{
if (!isServer) return;
networkManager.networkRules = gameplayRules;
Debug.Log("[Server] Switched to ServerStrict rules for gameplay.");
}
public void TransitionToLobby()
{
if (!isServer) return;
networkManager.networkRules = lobbyRules;
}
}Overriding Rules Per-Object via NetworkIdentity
Global rules apply to all objects by default. You can override them for a specific prefab by assigning a different NetworkRulesasset directly on that prefab's NetworkIdentity component. Per-object rules take precedence over global rules for every operation on that object.
Scenario Example — Prototype to Production
Many games start with Unsafe rules to iterate quickly, then tighten before shipping. The pattern below shows a single manager that swaps rules based on build type or feature flag.
using PurrNet;
using UnityEngine;
public class AuthorityBootstrap : MonoBehaviour
{
[Header("Rules assets")]
[SerializeField] private NetworkRules unsafeRules; // for prototyping
[SerializeField] private NetworkRules serverOwnerRules; // for co-op release
[SerializeField] private NetworkRules serverStrictRules;// for competitive release
[Header("Build flags")]
[SerializeField] private bool isPrototypeBuild = false;
[SerializeField] private bool isCompetitive = false;
private NetworkManager _nm;
private void Awake()
{
_nm = GetComponent<NetworkManager>();
ApplyRules();
}
private void ApplyRules()
{
if (isPrototypeBuild)
{
_nm.networkRules = unsafeRules;
Debug.LogWarning("NetworkRules: UNSAFE — prototyping only!");
return;
}
_nm.networkRules = isCompetitive ? serverStrictRules : serverOwnerRules;
}
}Never ship with Unsafe rules
Unsaferules allow any client to spawn any prefab, destroy other players' objects, and overwrite any SyncVar. In a publicly accessible game this is trivially exploitable. Switch to ServerOwner or ServerStrict before any public playtest.Per-object rules for special cases