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 : MonoBehaviour

Inheritance: MonoBehaviourAgentSpawner

Remarks

AgentSpawner is a scene-placed component that automates NPC spawning at game start. It works alongside a CharacterSpawner component on the same GameObject:

  1. Start — Waits 5 seconds, then spawns SpawnCount agents at 5-second intervals. Only runs on the host (NetworkManager.IsHost).

  2. Each spawn — Instantiates the AgentPrefab as a networked object, waits for network readiness, spawns a character via the co-located CharacterSpawner, assigns a random name from a built-in list, and connects them via Agent.PossessCharacter().

The spawner includes a pool of 36 medieval-themed character names (e.g., "Heinro", "Corbet", "Valdri") used for random name assignment.

Quick Lookup

Goal
How

Spawn a single agent

agentSpawner.Spawn()

Configure spawn count

Set SpawnCount in Inspector

Set the agent prefab

Assign AgentPrefab in Inspector

Fields

Field
Type
Description

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:

  1. Instantiates the AgentPrefab as a network object at the spawner's position/rotation.

  2. Waits until agent.Network.IsSpawned is true.

  3. Spawns a character via the co-located CharacterSpawner.SpawnAsync().

  4. Assigns a random name from the built-in name pool.

  5. Calls agent.PossessCharacter(character) to connect them.

circle-exclamation

Spawn Flow

spinner

Requirements

  • Same GameObject — Requires a CharacterSpawner component on the same GameObject (accessed via GetComponent<CharacterSpawner>()).

  • Host-only — Spawning only executes when NetworkManager.IsHost is true. 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

circle-exclamation
circle-exclamation
circle-exclamation

See Also

  • Agent — the AI entity spawned and possessed

  • CharacterSpawner — spawns the character body for the agent

Last updated