Guides

Spawn Groups

Load another map, a prefab or a skybox into the running map — where it goes, what it spawns, when it is ready and when it is gone.

A spawn group is a world loaded into the server: the map itself is one, its 3D skybox another. ISource2ModSpawnGroups loads more of them into the running map — a second map moved somewhere under the floor, a prefab, another map's skybox — and unloads them again.

plugin.cpp
#include "source2mod/ISource2ModSpawnGroups.h"

SpawnGroupLoadInfo info;
info.worldName = "maps/prefabs/de_mirage/3dskybox_mirage";
info.name = "mirage_sky";                  // what FindByName() and `status` know it as
info.origin = Vector(0.0f, 0.0f, -4000.0f);

Source2ModSpawnGroup group = g_pSource2ModSpawnGroups->Load(info, [](Source2ModSpawnGroup group, bool loaded)
{
    META_CONPRINTF("spawn group %u %s\n", group, loaded ? "ready" : "gone");
});
if (!group)
    return;   // no map running, no such world, or the engine refused it

g_pSource2ModSpawnGroups comes with SOURCE2MOD_SAVEVARS(); the interface is ISource2ModSpawnGroups001 (plugin API 12), on ISource2ModAPI as SpawnGroups().

What to load

worldName is the world as the engine names it, without the extension:

World
"de_mirage"A whole map — maps/de_mirage.vpk or maps/de_mirage/world.vwrld_c
"maps/prefabs/de_mirage/3dskybox_mirage"A prefab a map is built from, here its skybox
"prefabs/misc/end_of_match"One of the game's own prefabs

A world that does not exist is refused up front — Load() returns 0. The engine itself would take the name, fail, and then fail the next map load with it.

Load info

FieldC++SourcePawn
WorldworldNameworldNameRequired
NamenamenameWhat FindByName() and status know it by; the world name when empty
Positionorigin, anglesorigin, anglesWhere the world's origin goes in the running map, and how it is turned
FlagsflagsflagsSpawnGroupLoadFlags, below
Entity lumpentityLumpName—An entity lump other than the world's main one
Entity filterentityFilterName—A filter the world's entities go through
Name fixuplocalNameFixuplocalNameFixupA prefix for the group's own targetnames, so two copies of one world do not answer to each other's inputs
Flag
SPAWNGROUP_LOAD_DONT_SPAWN_ENTITIESThe world and its resources, none of its entities
SPAWNGROUP_LOAD_SUPPRESS_MAP_ENTITIESNone of the map's own entity lump (what a prefab adds still comes)
SPAWNGROUP_LOAD_BLOCK_UNTIL_LOADEDAsks the engine for one go — on CS2 14197 Load() still returns first, so wait for the callback anyway
SPAWNGROUP_LOAD_SET_ACTIVEMakes it the active spawn group once loaded, what the map itself is
SPAWNGROUP_LOAD_DISABLE_BASE_LAYERLeaves the new world's world_layer_base disabled
SPAWNGROUP_LOAD_NO_STREAMING_DATASkips its streaming data (static props, lighting)

Ready and gone

The callback is told twice: once when the group is loaded and its entities are spawned (loaded true), and once when it is gone again (loaded false) — someone else unloaded it, or the map changed under it. A group your plugin unloads itself is not reported, and every group a plugin loaded is unloaded when the plugin unloads.

Loading takes at least a frame. Anything that needs the group's entities waits for the callback, or polls IsLoaded().

The other calls

C++ (g_pSource2ModSpawnGroups->)SourcePawn (Source2ModSpawnGroups.)
Unload(group)Unload(group)Unloads a group with its entities — yours, or any the engine has, the map's own included (careful). false for no such group
FindByName(name)FindByName(name)By the name it was loaded under through Source2Mod, else by world name — the map's own "de_dust2", its skybox, the game's prefabs; 0 for none
IsLoaded(group) / IsLoading(group)IsLoaded(group) / IsLoading(group)Fully loaded with entities spawned / still on its way
MakeActive(group)MakeActive(group)Makes it the active group, like SPAWNGROUP_LOAD_SET_ACTIVE
GetEntitySpawnGroup(entity)GetEntitySpawnGroup(entity)The group an entity belongs to; 0 for none

The few spawn group calls that used to be on the string tables methodmap in scripts are gone; a plugin compiled with the old three-argument Load(world, name, block) still runs.

Reference: ISource2ModSpawnGroups.

On this page