SpawnableSettings - jimdroberts/FishMMO GitHub Wiki
SpawnableSettings is a serializable class for FishMMO that configures the properties of a spawnable object, including respawn times, spawn chance, and Y offset for placement. It ensures that each spawnable object is properly set up for spawning, network synchronization, and correct world placement.
-
public NetworkObject NetworkObject
The network object to be spawned.
-
public float MinimumRespawnTime
The minimum respawn time (in seconds) for this object.
-
public float MaximumRespawnTime
The maximum respawn time (in seconds) for this object.
-
[Range(0f, 1f)] public float SpawnChance
The chance (0 to 1) that this object will be selected for spawning. Default is 0.5 (50%).
-
[ShowReadonly] public float YOffset
The vertical offset used when placing the object in the world, calculated from its collider.
-
public void OnValidate()
Validates the spawnable settings, ensuring the network object is spawnable and calculates YOffset from its collider. No parameters. Returns: void. No exceptions are thrown.
- Create a new SpawnableSettings instance and assign a NetworkObject to it.
- Set the MinimumRespawnTime, MaximumRespawnTime, and SpawnChance as needed.
- Call OnValidate to ensure the settings are correct and YOffset is calculated.
- Add the SpawnableSettings to an ObjectSpawner's Spawnables list.
// Example 1: Configuring spawnable settings in code
SpawnableSettings settings = new SpawnableSettings();
settings.NetworkObject = myNetworkObject;
settings.MinimumRespawnTime = 10f;
settings.MaximumRespawnTime = 30f;
settings.SpawnChance = 0.75f;
settings.OnValidate();
// Example 2: Adding settings to an ObjectSpawner
objectSpawner.Spawnables.Add(settings);
- Always call OnValidate after modifying settings to ensure the NetworkObject is spawnable and YOffset is correct.
- Use SpawnChance to control the frequency of each object's appearance when using weighted spawn types.
- Document the purpose and configuration of each SpawnableSettings instance for maintainability.