PUN Local Area Spawner Driver
Photon PUN Extension for the Local Area Spawner (New in 1.6.0)
Overview
PUNLocalAreaSpawnerDriver is the Photon Unity Networking (PUN) driver for LocalAreaSpawner in External mode.
It implements a master-only execution model:
Non-master clients detect trigger enter/exit locally, but do not apply region state.
Non-master clients send a request to the MasterClient.
The MasterClient decides the authoritative inside/outside state and broadcasts it to the room.
Only the MasterClient calls
LocalAreaSpawner.SetPlayerInRegion(...)(so region-based spawning occurs only on master).
This keeps region activation consistent and prevents multiple peers from independently driving spawning.
Requirements
Photon PUN 2 (
PUN_2_OR_NEWER)A
LocalAreaSpawneron the same GameObjectA trigger
Collideron the same GameObject (isTrigger = true)LocalAreaSpawnershould be set to ActivationMode.ExternalA
RuntimeSpawnermust exist in the scene (the region registers with it normally)
This driver enforces component requirements via:
[RequireComponent(typeof(Collider))][RequireComponent(typeof(LocalAreaSpawner))]
Inspector Reference
Target
Target (target)
The LocalAreaSpawner instance to drive. If not assigned, the driver will use GetComponent<LocalAreaSpawner>().
Filter
Activator Layers (activatorLayers)
Layer mask filter for which colliders are allowed to affect region presence.
Activator Tag (activatorTag) (optional)
Optional tag filter. If empty, any tag is allowed (layer filter still applies).
Matching checks:
Collider object tag
Attached Rigidbody GameObject tag
Root transform tag
Networking
Cache State For Late Joiners (cacheStateForLateJoiners)
If enabled, the last inside/outside state is cached in the room so late joiners receive the current state.
Implementation details:
Uses
RaiseEventwithEventCaching.AddToRoomCacheGlobalfor the authoritative Set event.
Identity
Trigger Id (triggerId)
Stable ID used to match requests/sets across clients.
If empty, a deterministic hierarchy-path id is generated at runtime (scene path style).
For best results in additive/procgen workflows, author a stable id explicitly.
Debug
Enable Logging (enableLogging)
Enables local debug logs.
Verbosity (logVerbosity)
ErrorsOnly
Normal
Verbose
Note: logs are local-only.
Network Protocol
This driver uses PhotonNetwork.RaiseEvent with two event types (defined by your PunTriggerEvents constants):
RegionInsideRequest(client → MasterClient)Payload:
[triggerId, inside]Not cached
RegionInsideSet(MasterClient → All)Payload:
[triggerId, inside]Cached optionally if
cacheStateForLateJoinersis enabled
Runtime Behavior
Trigger detection
Any peer can detect trigger enter/exit locally:
If a valid activator collider enters:
MasterClient: authoritatively handles enter
Non-master: sends a request to MasterClient
If a valid activator collider exits:
MasterClient: authoritatively handles exit
Non-master: sends a request to MasterClient
Authoritative application (Master-only)
When the MasterClient receives a request (or detects enter/exit locally):
It updates its authoritative
_isInsideNetIt broadcasts a
RegionInsideSetevent to all clientsWhen that Set event is received:
Only the MasterClient applies:
target.SetPlayerInRegion(inside)
This means:
Region-based spawning and region state changes occur on master only.
Late joiners can be brought up to date (if caching is enabled).
Recommended Setup
Add a
LocalAreaSpawnervolume to your sceneSet its Trigger Driver Mode to External
Add
PUNLocalAreaSpawnerDriverto the same GameObjectEnsure the GameObject has a trigger
Collider(isTrigger = true)Configure filters:
Activator Layers: your player layer(s)
Activator Tag: optional (leave empty to disable)
If you support late join:
Enable Cache State For Late Joiners
Set a stable Trigger Id (recommended)
Runtime Snapshot (Editor / Development Builds)
The inspector snapshot maps to these read-only debug properties:
Is Connected And Ready
Is MasterClient
Inside (Net/Master)
LocalAreaSpawner reference
Trigger Id
Cache Late Joiners
Usage Notes
External mode is required
This driver is intended to drive LocalAreaSpawner via:
SetPlayerInRegion(bool)
If the region is left in UnityPhysics mode, you can end up with both:
Unity trigger callbacks mutating local state, and
network driver mutating state, which creates inconsistent results.
Last updated