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 LocalAreaSpawner on the same GameObject

  • A trigger Collider on the same GameObject (isTrigger = true)

  • LocalAreaSpawner should be set to ActivationMode.External

  • A RuntimeSpawner must 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 RaiseEvent with EventCaching.AddToRoomCacheGlobal for 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):

  1. RegionInsideRequest (client → MasterClient)

    • Payload: [triggerId, inside]

    • Not cached

  2. RegionInsideSet (MasterClient → All)

    • Payload: [triggerId, inside]

    • Cached optionally if cacheStateForLateJoiners is 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 _isInsideNet

  • It broadcasts a RegionInsideSet event to all clients

  • When 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).


  1. Add a LocalAreaSpawner volume to your scene

  2. Set its Trigger Driver Mode to External

  3. Add PUNLocalAreaSpawnerDriver to the same GameObject

  4. Ensure the GameObject has a trigger Collider (isTrigger = true)

  5. Configure filters:

    • Activator Layers: your player layer(s)

    • Activator Tag: optional (leave empty to disable)

  6. 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