Class ObjectSpawner
- Namespace
- FishMMO.Server.Implementation.World.SceneServer.Spawner
- Assembly
- FishMMO.Server.dll
Design-time placement of a spawner in a world scene. Does nothing at runtime.
[AddComponentMenu("FishMMO/Server/Object Spawner")]
[DisallowMultipleComponent]
public class ObjectSpawner : MonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourObjectSpawner
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.MemberwiseClone()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
Authoring only. The server never reads this component. The spawn table baker
(FishMMO Dashboard → World → Spawn Tables → Rebuild Spawn Tables, and automatically whenever a world scene is
saved or a build starts) copies every spawner in a scene into that scene's
SceneSpawnTable, and SpawnerSystem runs the table. World scenes
are built into one bundle shared by clients and servers, so the spawner's GameObject is
tagged EditorOnly and removed from every build: a client never receives what a
spawner produces, where, or how often.
It used to be a NetworkBehaviour that ran itself on the server and disabled itself
everywhere else, which shipped every spawner's configuration to every player and spent a
scene network object on each one.
Fields
BoundingBoxSize
The size of the bounding box used for random spawn position selection.
public Vector3 BoundingBoxSize
Field Value
- Vector3
EditorOnlyTag
The tag that keeps a spawner out of every build.
public const string EditorOnlyTag = "EditorOnly"
Field Value
GizmoColor
The color used to draw the spawner's gizmo in the editor.
public Color GizmoColor
Field Value
- Color
InitialRespawnTime
Respawn delay, in seconds, for an object that has no settings and no cadence of its own.
public float InitialRespawnTime
Field Value
InitialSpawnCount
The number of objects to spawn when the scene starts.
public int InitialSpawnCount
Field Value
KeepOutCircles
Circles (x, keep-clear radius, z) nothing from this spawner may spawn inside: the towns a wildlife area reaches into, written by the cut (WildlifeSpawnerCut). Empty for every other spawner.
[Tooltip("Circles (x, radius, z) nothing spawns inside: settlements a wildlife area overlaps. Written by the cut.")]
public List<Vector3> KeepOutCircles
Field Value
- List<Vector3>
MaxSpawnCount
The maximum number of objects that can be spawned by this spawner.
[Tooltip("The maximum number of objects that can be spawned by this spawner.")]
public int MaxSpawnCount
Field Value
OrConditions
If any of these conditions return true, the object will respawn. This list is checked first (logical OR).
[SerializeReference]
public List<RespawnCondition> OrConditions
Field Value
Pack
Makes this spawner's NPCs one pack: its tactic and focus. Each NPC entry's
PackRole says what that member does in it.
[Header("Pack")]
public NPCPackSettings Pack
Field Value
Remarks
One spawner is one pack. A pack whose members all die is released, and the next spawn founds a new one; a respawn while any member stands rejoins it. For an exact composition that comes back as authored — one tank, one healer, two DPS — list each member as its own entry, spawn Linear and turn UniqueSpawnables on, so a respawn refills the entry that died. Off by default.
PrewarmHeadroom
Extra instances reserved beyond MaxSpawnCount.
[Tooltip("Extra pooled instances beyond MaxSpawnCount, as slack for prefabs shared between spawners.")]
[Min(0)]
public int PrewarmHeadroom
Field Value
Remarks
Slack, not a requirement. A corpse holds its spawner slot for the whole of its decay — the despawn is what frees the slot and starts the respawn clock, and a corpse does not reach it until the decay timer expires — so this spawner can never have more than MaxSpawnCount live instances and the reservation alone would do.
The headroom is kept because the pool is shared: SpawnerPool de-duplicates reservations across every spawner using the same prefab, taking the largest single demand rather than the sum, so a prefab used by many spawners at once genuinely can need more instances than any one spawner reserved. This covers that without making the reservation quadratic.
PrewarmPool
When true, every prefab this spawner can produce is instantiated into the object pool at scene start, up to MaxSpawnCount each.
[Header("Pooling")]
[Tooltip("Instantiate this spawner's prefabs into the pool at scene start for a fixed memory footprint.")]
public bool PrewarmPool
Field Value
Remarks
This is what makes a map's memory footprint deterministic. Without it the pool fills lazily — the first NPC of each kind is instantiated the moment a player walks into range — so a freshly loaded map hitches as it is explored and only reaches its true heap size once every spawner has fired at least once. Neither behaviour can be planned against.
Turn it off for spawners whose prefabs are large and rarely used, where paying the cost on demand is preferable to paying it always.
RandomRespawnTime
If true, a random respawn time is selected within the minimum and maximum range. Otherwise, the maximum respawn time is used.
[Tooltip("If true a random number will be selected within the minimum and maximum range provided. Otherwise the maximum respawn time will be used.")]
public bool RandomRespawnTime
Field Value
RandomSpawnPosition
If true, a random spawn position is picked inside the bounding box using the current position as the center.
[Tooltip("If true a random spawn position will be picked inside of the bounding box using the current position as the center.")]
public bool RandomSpawnPosition
Field Value
RespawnCheckIntervalMaximum
Longest delay between respawn checks, in seconds.
[Tooltip("Longest delay between respawn checks, in seconds. Each check picks a fresh random delay in this range so spawners do not all poll on the same frame.")]
public float RespawnCheckIntervalMaximum
Field Value
RespawnCheckIntervalMinimum
Shortest delay between respawn checks, in seconds.
[Tooltip("Shortest delay between respawn checks, in seconds. Respawn deadlines are kept on the server's monotonic clock, independent of these checks, so this only sets how soon after a deadline the object appears - it does not change respawn timing itself.")]
public float RespawnCheckIntervalMinimum
Field Value
SpawnType
The type of spawn selection (Linear, Random, Weighted).
public ObjectSpawnType SpawnType
Field Value
Spawnables
The list of spawnable settings used to configure each spawnable object. Supports polymorphic subclasses via UnityEngine.SerializeReference for type-specific data injection.
[SerializeReference]
public List<SpawnableSettings> Spawnables
Field Value
SphereRadius
SphereCast radius used for spawning objects in the world.
[Tooltip("SphereCast radius used for spawning objects in the world.")]
public float SphereRadius
Field Value
TrueConditions
All conditions must return true for the object to respawn. This list is checked second (logical AND).
[SerializeReference]
public List<RespawnCondition> TrueConditions
Field Value
UniqueSpawnables
When true, at most one live instance of each entry in Spawnables may exist at a time.
[Tooltip("Allow at most one live instance of each spawnable. Off by default. Turn on when every entry is a distinct individual that should never be duplicated.")]
public bool UniqueSpawnables
Field Value
Remarks
Off by default, because the normal case is a spawner filling a zone with several of the same creature. Turn it on where each entry names a distinct individual — a zone listing several named NPCs would otherwise draw the same one repeatedly and stand two copies of it side by side, since the spawn index is chosen without regard to what is already alive.
This caps each entry at one, not the spawner: MaxSpawnCount still governs the total, so with this on the effective ceiling is the smaller of MaxSpawnCount and the number of assigned spawnables.
Methods
EnforceEditorOnlyTag(ObjectSpawner)
Tags a spawner's GameObject EditorOnlyTag, recording an undo step and dirtying its scene or prefab.
public static bool EnforceEditorOnlyTag(ObjectSpawner spawner)
Parameters
spawnerObjectSpawnerThe spawner.
Returns
- bool
True if the tag was changed.