Class SpawnableSettings
Base serializable settings for configuring a spawnable object. Supports polymorphic subclassing via UnityEngine.SerializeReference for type-specific data injection (e.g., items, NPCs). Use the SubclassSelector attribute on the containing field/list for Inspector support.
[Serializable]
public class SpawnableSettings
- Inheritance
-
SpawnableSettings
- Derived
- Inherited Members
Fields
MaximumRespawnTime
The maximum respawn time (in seconds) for this object.
[Tooltip("Longest respawn delay in seconds. For NPCs, leave at 0 to use the prefab's own value.")]
[Min(0)]
public float MaximumRespawnTime
Field Value
Remarks
See MinimumRespawnTime for the override semantics.
MinimumRespawnTime
The minimum respawn time (in seconds) for this object.
[Tooltip("Shortest respawn delay in seconds. For NPCs, leave at 0 to use the prefab's own value.")]
[Min(0)]
public float MinimumRespawnTime
Field Value
Remarks
Subclasses whose prefab carries its own respawn cadence treat this as an OVERRIDE that is only consulted when set — see NPCSpawnableSettings. For everything else it is simply the authored value.
NetworkObject
The network object prefab to be spawned.
public NetworkObject NetworkObject
Field Value
- NetworkObject
SpawnChance
The chance (0 to 1) that this object will be selected for spawning. Default is 0.5 (50%).
[Range(0, 1)]
public float SpawnChance
Field Value
YOffset
The vertical offset used when placing the object in the world, calculated from its collider.
public float YOffset
Field Value
Methods
OnSpawned(NetworkObject, ObjectSpawner)
Called after the network object has been instantiated but before it is spawned on the network. Override in subclasses to inject type-specific data into the spawned object.
public virtual void OnSpawned(NetworkObject nob, ObjectSpawner spawner)
Parameters
nobNetworkObjectThe instantiated network object to configure.
spawnerObjectSpawnerThe spawner that created this object.
OnValidate()
Validates the spawnable settings, ensuring the network object is spawnable and calculates YOffset from its collider.
public virtual void OnValidate()
ResolveRespawnTimeRange(out float, out float)
Resolves the respawn delay range this spawnable should use.
public virtual void ResolveRespawnTimeRange(out float minimum, out float maximum)
Parameters
minimumfloatReceives the shortest respawn delay in seconds.
maximumfloatReceives the longest respawn delay in seconds.
Remarks
Exists so the spawner asks the settings for a range rather than reading the two fields directly. That indirection is the whole point: a subclass whose prefab carries its own respawn cadence can answer with the prefab's values when the spawner has not overridden them, and the spawner does not need to know which subclass it is holding.
The base implementation has no prefab defaults to fall back on, so it returns the authored fields unchanged.