Skip to main content

SpawnerBase

An abstract class in Root.Township, the global namespace.

Base for networked spawners that spawn a prefab at themselves, at random or sequential spawn points, or at a forced position, with optional attribute overrides and material. Server side.

Constructors​

MemberWhat it is
protected SpawnerBase()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

14 private and internal fields
MemberWhat it is
private AttributeSingleValue[] attributesAttribute overrides written into the spawn data for every spawned entity.
private bool isActiveBacking field for IsActive. While false, spawning does nothing.
private bool isChildingSpawnedSpawns entities as saved children parented to this spawner instead of into its chunk.
private bool isRotationRandomGives spawned entities a random rotation instead of the spawn point's.
private bool isRotationRandomYOnlyLimits random rotation to a turn about Y.
private PhysicalMaterialPart materialPartPhysical material copied onto spawned entities that have a PhysicalMaterialPart.
private SpawnMethod methodHow spawn points are chosen: sequence, random, or the spawner itself.
private int nextIdIndex of the last spawn point used in sequence mode.
private Vector3 nextPositionPosition chosen for the entity being spawned.
private Quaternion nextRotationRotation chosen for the entity being spawned.
private Vector3 positionCacheSpawner position captured at the start of a spawn when there are no spawn points.
private float radiusRandom scatter radius around the spawner when there are no spawn points.
private Quaternion rotationCacheSpawner rotation captured with positionCache.
private Transform[] spawnPointsOptional transforms to spawn at.

Properties​

MemberWhat it is
Vector3? ForcePosition { get; private set; }A one-time position set by SpawnAt, used for the next spawn then cleared.
bool IsActive { get; set; }When false, spawning does nothing.
NetworkEntity LastSpawned { get; private set; }The most recently spawned entity.
1 private and internal property
MemberWhat it is
private Transform NextSpawnPoint { get; }Next spawn point by method: in sequence, at random, or this transform.

Methods​

MemberWhat it is
abstract void Spawn()Spawns the subclass's item. The protected overload spawns count copies of a prefab into the spawner's chunk, or as saved children if set to child them.
void SpawnAt(Vector3 location)Spawns once at a given position, with a random rotation.
protected virtual void OnSpawn(NetworkEntity spawned)Called after each entity spawns. Empty by default.
protected void Spawn(NetworkPrefab prefab, int count)Spawns the subclass's item. The protected overload spawns count copies of a prefab into the spawner's chunk, or as saved children if set to child them.
5 private and internal methods
MemberWhat it is
private void EvaluatePosition()Picks the next spawn position and rotation: a forced position, a random spot within radius, or the next spawn point.
private void OnDrawGizmosSelected()Draws the spawn radius as a faint sphere.
private void Position(NetworkEntity entity)Spawn callback that places the new entity at the chosen position and rotation.
private void PreChunk(NetworkEntity entity)Spawn callback that applies materialPart's physical material to the new entity, if set.
private Quaternion RandomRotation()A random rotation, or a random turn about Y only if isRotationRandomYOnly.