AgentSpawner
MonoBehaviour that spawns networked agent-character pairs on the host. Creates an Agent prefab instance, waits for network readiness, spawns a Character via CharacterSpawner, assigns a random name, and wires them together via possession.
Definition
Namespace: Paragon
Assembly: Townskeep.dll
public class AgentSpawner : MonoBehaviourInheritance: MonoBehaviour → AgentSpawner
Remarks
AgentSpawner is a scene-placed component that automates NPC spawning at game start. It works alongside a CharacterSpawner component on the same GameObject:
Start — Waits 5 seconds, then spawns
SpawnCountagents at 5-second intervals. Only runs on the host (NetworkManager.IsHost).Each spawn — Instantiates the
AgentPrefabas a networked object, waits for network readiness, spawns a character via the co-locatedCharacterSpawner, assigns a random name from a built-in list, and connects them viaAgent.PossessCharacter().
The spawner includes a pool of 36 medieval-themed character names (e.g., "Heinro", "Corbet", "Valdri") used for random name assignment.
Quick Lookup
Spawn a single agent
agentSpawner.Spawn()
Configure spawn count
Set SpawnCount in Inspector
Set the agent prefab
Assign AgentPrefab in Inspector
Fields
AgentPrefab
Agent
The networked agent prefab to instantiate
SpawnCount
int
Number of agents to spawn automatically on Start
Methods
Spawn
Spawns a single agent-character pair. Async operation that:
Instantiates the
AgentPrefabas a network object at the spawner's position/rotation.Waits until
agent.Network.IsSpawnedistrue.Spawns a character via the co-located
CharacterSpawner.SpawnAsync().Assigns a random name from the built-in name pool.
Calls
agent.PossessCharacter(character)to connect them.
Async void — Spawn() is async void, meaning exceptions are not awaitable. Failures during network instantiation or character spawning will propagate as unobserved exceptions.
Spawn Flow
Requirements
Same GameObject — Requires a
CharacterSpawnercomponent on the same GameObject (accessed viaGetComponent<CharacterSpawner>()).Host-only — Spawning only executes when
NetworkManager.IsHostistrue. Clients skip the spawn loop entirely.Network context — Both the agent prefab and character are spawned as networked objects. A valid network session must be active.
Common Pitfalls
Requires co-located CharacterSpawner — The spawner calls GetComponent<CharacterSpawner>() in Awake(). If no CharacterSpawner is on the same GameObject, Spawn() will throw a NullReferenceException.
5-second startup delay — The spawner waits 5 seconds before the first spawn and 5 seconds between each subsequent spawn. This is hardcoded and not configurable.
Name pool is fixed — The 36 character names are hardcoded as a static readonly array. Names may repeat across agents since selection is Random.Range without deduplication.
See Also
Agent — the AI entity spawned and possessed
CharacterSpawner — spawns the character body for the agent
Last updated