Runtime Spawner 1.5.1
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
Loading...
Searching...
No Matches
MegaCrush.Spawner.FusionAdapter.FusionObjectFactory Class Referencesealed

Implementation of IObjectFactory that spawns networked objects using Photon Fusion. More...

Inheritance diagram for MegaCrush.Spawner.FusionAdapter.FusionObjectFactory:
MegaCrush.Spawner.IObjectFactory MegaCrush.Spawner.IPrewarmableFactory

Public Member Functions

 FusionObjectFactory (NetworkRunner runner, bool serverOnly=true)
 Creates a new Fusion-backed object factory.
 
ISpawnHandle Spawn (SpawnRequest r)
 Spawns a networked object using NetworkRunner.Spawn(NetworkObject, Vector3, Quaternion, PlayerRef).
 
Task< ISpawnHandleSpawnAsync (SpawnRequest r)
 Asynchronously spawns a networked object.
 
void Prewarm (SpawnEntry entry, int count)
 Prewarms the pool for a given prefab via the runner’s INetworkObjectProvider.
 

Private Attributes

readonly NetworkRunner _runner
 
readonly bool _serverOnly
 

Detailed Description

Implementation of IObjectFactory that spawns networked objects using Photon Fusion.

Integrates with a live NetworkRunner to perform network instantiation via NetworkRunner.Spawn(NetworkObject, Vector3, Quaternion, PlayerRef) and teardown via NetworkRunner.Despawn(NetworkObject). Spawned instances are standard Fusion NetworkObjects and replicate to clients automatically.

In typical usage, the RuntimeSpawner runs only on the authoritative instance (host/server). When serverOnly is true, client calls to Spawn(SpawnRequest) are ignored and return null; objects appear on clients through replication.

Pooling and prewarming are delegated to the runner’s INetworkObjectProvider, e.g. FusionPoolObjectProviderBehaviour (MonoBehaviour on the runner) or FusionPoolProvider (core provider passed via StartGameArgs.ObjectProvider). Those providers may internally bridge to a project-specific IPoolAdapter for prefab reuse.

See also
IObjectFactory, IPrewarmableFactory, NetworkRunner, NetworkObject, FusionPoolObjectProviderBehaviour, FusionPoolProvider

Constructor & Destructor Documentation

◆ FusionObjectFactory()

MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.FusionObjectFactory ( NetworkRunner runner,
bool serverOnly = true )

Creates a new Fusion-backed object factory.

Parameters
runnerA running NetworkRunner responsible for spawn/replication.
serverOnlyIf true, only the authoritative host/server performs spawns. Non-authoritative callers get null and no error is logged. Set to false only with a custom flow that allows client-initiated spawns under controlled conditions.

Member Function Documentation

◆ Prewarm()

void MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.Prewarm ( SpawnEntry entry,
int count )

Prewarms the pool for a given prefab via the runner’s INetworkObjectProvider.

Parameters
entrySpawn entry referencing the prefab to prewarm.
countNumber of instances to prepare for reuse.

When the runner’s NetworkRunner.ObjectProvider is FusionPoolObjectProviderBehaviour or FusionPoolProvider, this forwards to their respective Prewarm(GameObject, int) method. If the provider does not support pooling or is a different implementation, this method safely no-ops (with a one-time warning).

Requires a running runner and a valid prefab reference; invalid inputs are ignored without logging.

Implements MegaCrush.Spawner.IPrewarmableFactory.

◆ Spawn()

ISpawnHandle MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.Spawn ( SpawnRequest r)

Spawns a networked object using NetworkRunner.Spawn(NetworkObject, Vector3, Quaternion, PlayerRef).

Parameters
rSpawn request containing prefab (must include NetworkObject), transform, and optional owner (as PlayerRef or PlayerRef.None).
Returns
An ISpawnHandle wrapping the spawned instance, or null if spawning is skipped/refused (no runner, missing NetworkObject, or non-authoritative when serverOnly is enabled).

Requires authority when serverOnly is true (i.e., _runner must be a server/host). Clients will receive the object through Fusion replication.

The returned handle’s despawn delegates to NetworkRunner.Despawn(NetworkObject) when the caller has authority; otherwise the request is ignored.

Implements MegaCrush.Spawner.IObjectFactory.

◆ SpawnAsync()

Task< ISpawnHandle > MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.SpawnAsync ( SpawnRequest r)

Asynchronously spawns a networked object.

Parameters
rThe spawn request to process.
Returns
The ISpawnHandle result of Spawn(SpawnRequest).

Fusion’s spawn API is immediate; this method returns a completed task for API symmetry.

Implements MegaCrush.Spawner.IObjectFactory.

Member Data Documentation

◆ _runner

readonly NetworkRunner MegaCrush.Spawner.FusionAdapter.FusionObjectFactory._runner
private

◆ _serverOnly

readonly bool MegaCrush.Spawner.FusionAdapter.FusionObjectFactory._serverOnly
private

The documentation for this class was generated from the following file: