Skip to content
smartargs
VantageDocumentation

Spawning reference

The mob spawner, its weighted prefab pool, and the hooks that decide how gameplay creates and removes objects. For how to use it, see Spawning.

VtMobSpawner

Component. Add it with Add Component → Vantage → Spawning → VtMobSpawner.

Scene-placed spawn point. Keeps Count units alive around its position, respawns each one VtUnitDefinition.respawnTime seconds after it dies, and can pick from a weighted pool of prefabs, scatter a pack inside a radius, hand spawned units a patrol route, reuse dead instances instead of instantiating, and spawn only in some day phases of the scene’s VtWorldClock.

Inspector fields

Field Type Default Range Description
Prefab (prefab) GameObject None Prefab to spawn. Must contain a VtUnit. Its definition’s Respawn Time schedules respawns.
Variants (variants) VtSpawnVariant[] Empty Optional weighted pool. When it has entries, every spawn picks one of them instead of Prefab.
Count (count) int 1 ≥ 1 How many units this point keeps alive at once. 1 = one monster, 3 = a pack.
Spawn Radius (spawnRadius) float 0 ≥ 0 Units appear at a random point within this radius of the spawner. 0 = exactly here.
Spawn On Awake (spawnOnAwake) bool On Fill the spawn point on Awake. Off lets you call TrySpawn or SpawnAll yourself.
Respawns After Death (respawnsAfterDeath) bool On Respawn a unit after it dies, after its definition’s Respawn Time. Respawn Time 0 disables it per unit.
Reuse Instances (reuseInstances) bool Off Revive the dead instance in place on respawn instead of instantiating a new one. The corpse stays where it fell until its respawn timer fires.
Corpse Linger Seconds (corpseLingerSeconds) float 0 ≥ 0 Seconds a corpse stays before it is removed. 0 = leave it. Ignored when Reuse Instances is on.
Patrol Route (patrolRoute) VtPatrolRoute None Optional patrol route the spawned units walk. Adds a VtRoaming to units whose definition has none.
Active Phases (activePhases) VtDayPhaseDefinition[] Empty Day phases this point spawns in, read from the scene’s VtWorldClock. Empty = always. With Spawn On Awake the point fills when one of these phases begins.
Despawn Outside Phases (despawnOutsidePhases) bool On Remove the live units and corpses when the clock leaves the Active Phases.

Scripting API

Member Description
VtUnit CurrentUnit { get; } The first live unit, or null. Packs expose every unit through LiveUnits.
bool HasLiveUnit { get; } True while at least one spawned unit is alive.
IReadOnlyList<VtUnit> LiveUnits { get; } Every spawned unit that is currently alive.
int LiveCount { get; } Number of live units.
int PendingRespawns { get; } Number of respawn timers currently running.
float RespawnSecondsRemaining { get; } Seconds until the next respawn, 0 when none is pending.
GameObject Prefab { get; } The default prefab.
int Count { get; set; } How many units the point keeps alive.
VtPatrolRoute PatrolRoute { get; set; } Patrol route handed to every spawned unit’s VtRoaming.
VtDayPhaseDefinition[] ActivePhases { get; set; } Day phases this point spawns in. Empty = always.
bool DespawnOutsidePhases { get; set; } Remove live units and corpses when the clock leaves ActivePhases.
bool IsInActivePhase { get; } True when the scene clock is in one of ActivePhases, when the list is empty, or when the scene has no VtWorldClock.
event Action<VtUnit> OnUnitSpawned Fires after every spawn and every revive.
event Action<VtUnit> OnUnitDied Fires when a spawned unit dies.
event Action<float> OnRespawnTimerStarted Fires when a respawn timer starts, with its length in seconds.
void Initialize() Follow the scene clock’s phases and fill the point when Spawn On Awake is set. Idempotent.
void SetRandom(IVtRandom random) Replace the random source, for deterministic variant picks and scatter such as in replays. Null restores Unity’s random.
int SpawnAll() Spawn until Count units are alive. Returns how many were spawned.
virtual bool TrySpawn(out VtUnit spawned) Spawn one unit. Returns false on a missing prefab, a prefab without a VtUnit, a full point, outside the ActivePhases, or a replica-side call.
void Despawn() Remove every live unit, corpse and timer. Does not start respawns.
void Tick(float deltaTime) Advance respawn and corpse timers by deltaTime seconds. Authority-only.
protected virtual GameObject InstantiatePrefab(GameObject source, Vector3 position, Quaternion rotation) Create the instance. Override to register it with your networking layer.

VtSpawnVariant

Serializable struct.

One entry of a VtMobSpawner weighted prefab pool.

Inspector fields

Field Type Default Range Description
Prefab (prefab) GameObject None Prefab with a VtUnit at its root.
Weight (weight) float 0 ≥ 0 Relative chance. 3 next to 1 spawns this prefab three times out of four. 0 never spawns.

VtSpawning

Static class.

Creates and removes the objects gameplay spawns while the game runs: loot on the ground, placed buildings, projectiles, summons, spawner mobs and buildings restored from a save. The default instantiates and destroys locally. A networked game points InstantiateFn and DespawnFn at its framework’s spawn calls once at bootstrap, as the co-op sample’s spawn hooks do. A game with object pools points them at its pools.

Scripting API

Member Description
static Func<GameObject, Vector3, Quaternion, GameObject> InstantiateFn Creates an instance of a prefab at a pose. Null uses UnityEngine.Object.Instantiate.
static Action<GameObject> DespawnFn Removes an instance. Null destroys it.
static GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation) Create an instance of prefab through InstantiateFn. Null for a null prefab.
static void Despawn(GameObject instance) Remove instance through DespawnFn.
static void ResetHooks() Restore the local defaults.