Skip to main content

SpawnArea

A class in Root.Township, the global namespace.

A circle on the ground where things (or players) spawn. Gives repeatable positions by index, raycast onto valid ground away from blocking layers. Named areas are listed in InstanceMap.

Constructors​

MemberWhat it is
SpawnArea()Creates a SpawnArea with default values.

Fields​

MemberWhat it is
static Dictionary<SpawnAreaIdentifier, SpawnArea> InstanceMapEvery spawn area with a non-default identifier, by identifier.
9 private and internal fields
MemberWhat it is
private float avoidCastRadiusRadius checked around a spot for avoid-layer objects. Below 0 skips the check.
private LayerMask avoidLayersLayers that block a spawn spot, both when hit by the ground ray and nearby.
private LayerMask groundLayersLayers counted as ground for the downward raycast.
private SpawnAreaIdentifier identifierBacking field for Identifier. Non-default areas register in InstanceMap, for example the respawn point.
private bool isAligningNormalWhether spawn rotation tilts to match the ground normal.
private float maxAcceptableAngleDotLowest ground normal y (set from an angle) a spot can have. -1 allows any slope.
private int maxIterationsRandom tries before falling back to the area's centre (100 by default).
private int seedRandom seed picked in Awake, so the same index gives the same spot during a session.
private float sizeRadius of the circle spawn spots are picked in.

Properties​

MemberWhat it is
SpawnAreaIdentifier Identifier { get; }Which named spawn area this is.

Methods​

MemberWhat it is
void Awake()Picks a random seed and adds the area to InstanceMap if it's named.
Vector3 GetRandomSpawnPosition()A valid position from a random index.
SpawnPoint GetSpawnPosition(int index)The spawn point for an index. The same index gives the same point while the seed lasts. Falls back to the centre.
3 private and internal methods
MemberWhat it is
private void OnDestroy()Removes the area from InstanceMap.
private void ISpawnPositions.SetSize(float size)Sets the spawn circle's radius.
private bool ValidPosition(ref Vector3 position, ref Quaternion rotation)Raycasts down to ground near the point and checks the slope and that nothing in the avoid layers is nearby.

Used in​

Members of other types that take, return or hold a SpawnArea: