SpawnableSettings - jimdroberts/FishMMO GitHub Wiki

Description

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.


API Access

Fields

  • 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.

Methods

  • 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.


Basic Usage

Setup

  1. Create a new SpawnableSettings instance and assign a NetworkObject to it.
  2. Set the MinimumRespawnTime, MaximumRespawnTime, and SpawnChance as needed.
  3. Call OnValidate to ensure the settings are correct and YOffset is calculated.
  4. Add the SpawnableSettings to an ObjectSpawner's Spawnables list.

Example

// 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);

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️