Coordinated Spawns - SubnauticaModding/Nautilus GitHub Wiki
Coordinated Spawns system allows you to spawn entities via world positions and rotations instead of the traditional LootDistribution system the game uses.
SMLHelper introduces a new handler named CoordinatedSpawnsHandler under the SMLHelper.V2.Handlers namespace, which registers spawns to the system.
| SpawnInfo |
|---|
Registers a Coordinated Spawn.
-
SpawnInfo spawnInfo
Information about where and what entity should spawn.
Registers multiple Coordinated Spawns.
RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, List<Vector3> coordinatesToSpawnTo)
Registers multiple Coordinated Spawns for one single passed TechType.
-
TechTypetechTypeToSpawn
TechType entity to spawn. -
List<Vector3>coordinatesToSpawnTo
World positions to spawn to.
RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, Dictionary<Vector3, Vector3> coordinatesAndRotationsToSpawnTo)
[Deprecated]
Registers multiple Coordinated Spawns with rotations for one single passed TechType.
-
TechTypetechTypeToSpawn
TechType entity to spawn. -
Dictionary<Vector3, Vector3>coordinatesAndRotationsToSpawnTo
The world positions (key) and rotations (value) the entity should spawn to.
This method existed prior to Spawnable.SpawnLocation and was only used in the Spawnable class.
Usage of this method is ill-advised as the SpawnInfo already covers all use-cases.
The following examples demonstrate the usage of CoordinatedSpawnsHandler methods.
using SMLHelper.V2.Handlers;
using UnityEngine;
[QModCore]
public static class MyMainClass
{
[QModPatch]
public static void MyPatch()
{
SpawnInfo reaperInfo = new SpawnInfo(TechType.ReaperLeviathan, new Vector3(280f, -1400f, 47f)); // Lava Lakes
CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(reaperInfo);
var spawnInfos = new List<SpawnInfo>()
{
new SpawnInfo(TechType.Seamoth, Vector3.zero),
new SpawnInfo(TechType.SandShark, new Vector3(10, -4, 5), Vector3.up * 90f) // rotate its Y axis 90 degrees
}
CoordinatedSpawnsHandler.RegisterCoordinatedSpawns(spawnInfos);
// Spawns a batch of titaniums around 10, -3, 15 world position
var randomPositions = RandomPositions(new vector3(10f, -3f, 15f));
CoordinatedSpawnsHandler.RegisterCoordinatedSpawnsForOneTechType(
TechType.Titanium, randomPositions);
}
// Gets 5 random positions around the passed location.
private static List<Vector3> RandomPositions(Vector3 centerPosition)
{
var result = new List<Vector3>();
for (int i = 0; i < 5; i++)
{
result.Add(centerPosition + (Random.insideUnitSphere * i));
}
return result;
}
}Provides sufficient information for the Coordinated Spawns system to function.
public struct SpawnInfo : IEquatable<SpawnInfo>SpawnInfo(TechType techType, Vector3 spawnPosition) |
|---|
SpawnInfo(string classId, Vector3 spawnPosition) |
SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation) |
SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation) |
SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation) |
SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation) |