CharacterSpawner

Scene-placed MonoBehaviour for spawning networked characters. Supports both Inspector-configured spawning (via FactorableSpawner) and static spawning by character ID (via CharacterDatabase).

Definition

Namespace: Paragon.Townskeep.CharacterSystem Assembly: Townskeep.dll

public class CharacterSpawner : SerializedMonoBehaviour

Inheritance: SerializedMonoBehaviourCharacterSpawner

Remarks

CharacterSpawner provides two spawning patterns:

  1. Instance methods — Uses an Inspector-configured FactorableSpawner<Character, CharacterData> to spawn a specific character type at the spawner's transform.position. The factory and variant are selected in the Inspector.

  2. Static methods — Spawns any character by characterID using CharacterDatabase.GetFactory(). Does not require a scene instance.

All spawning goes through NetworkScriptableFactory.NetworkSpawn(), creating replicated NetworkObject instances via Unity Netcode.

The Spawn() button is available in the Inspector during Play Mode via [Button, ShowIf("@UnityEngine.Application.isPlaying")].

Quick Lookup

Goal
How

Spawn from Inspector-configured factory

spawner.Spawn(ownerID, predicted)

Spawn and wait for network ready

await spawner.SpawnAsync(ownerID, predicted)

Spawn any character by ID (static)

CharacterSpawner.Spawn(characterID, variantID, ownerID, predicted)

Spawn any character async (instance)

await spawner.SpawnAsync(characterID, variantID, ownerID, predicted)

Methods

Spawn (instance)

Spawns a character using the Inspector-configured FactorableSpawner, positioned at the spawner's transform.

Parameter
Type
Description

ownerID

ulong?

Network owner client ID, or null for server-owned

predicted

bool

Whether to use client-side prediction

Returns: The spawned Character instance.

SpawnAsync (instance, configured factory)

Spawns via the configured factory and awaits until the NetworkObject.IsSpawned is true.

Spawn (static, by character ID)

Spawns any character by looking up its factory from CharacterDatabase. Uses variant index 0.

Parameter
Type
Description

characterID

int

The CharacterID to look up in CharacterDatabase

ownerID

ulong?

Network owner client ID

predicted

bool

Client-side prediction flag

Spawn (static, by character ID + variant)

Spawns any character with a specific variant.

Parameter
Type
Description

characterID

int

The CharacterID to look up

variantID

int

Data variant index (0 = source data)

ownerID

ulong?

Network owner client ID

predicted

bool

Client-side prediction flag

SpawnAsync (instance, by character ID)

Async spawn by character ID. Awaits NetworkObject.IsSpawned.

Usage Example

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated