Skip to content

Stop wheels and other subgrids counting as separate NPCs in area spawn limits - #468

Closed
Blaylock1988 wants to merge 4 commits into
MeridiusIX:masterfrom
GV-Server-Mods:fix/subgrid-spawn-count
Closed

Blaylock1988 wants to merge 4 commits into
MeridiusIX:masterfrom
GV-Server-Mods:fix/subgrid-spawn-count

Conversation

@Blaylock1988

@Blaylock1988 Blaylock1988 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Since 9ea651c, each wheel, rotor head, hinge top and piston top of an MES spawn gets the spawn's NpcData and counts toward the area spawn limit, so a rover with four wheels counts as five spawns. These are the four "Small Grid" entries next to the Tire Thieves Shikari in your GESAP output. The Entity List hides them because it only lists the root grid of a mechanical group.

GridsSpawned runs before suspensions, rotors and pistons attach their top parts, so GetBiggestGridInGroup returns each top-part grid itself:

static void GridsSpawned(List<IMyCubeGrid> grids, NpcData data, ImprovedSpawnGroup spawnGroup, MySpawnGroupDefinition.SpawnGroupPrefab prefab, long factionOwner)
{
foreach(MyCubeGrid grid in grids)
{
var mainGrid = grid.GetBiggestGridInGroup();
if(mainGrid == null) throw new Exception("Main grid was null when trying to spawn prefab.");
if(mainGrid.Storage == null)
mainGrid.Storage = new MyModStorageComponent();
if(!mainGrid.Storage.ContainsKey(StorageTools.NpcDataKey))
{
mainGrid.Storage[StorageTools.NpcDataKey] = SerializationHelper.ConvertClassToString<NpcData>(data);
}
}

Change

  • GridsSpawned groups the spawned grids along the top parts their bases are about to attach (the pending TopBlockId of each rotor, hinge, piston and suspension) and gives the NpcData to each group's biggest grid by WorldAABB volume, as GetBiggestGridInGroup picks it once the tops attach. Grids that aren't joined that way, like vehicles on connectors or landing gear, keep their own NpcData.
  • GetAreaNpcCount and GetAreaNpcs count each UniqueSpawnIdentifier once. This also covers saves where the top parts already have the data, and a prefab made of several separate grids counts once again, as before 9ea651c.

Testing

Single player only. Three rovers (a body plus 4 wheels each) in one Planetary Installation spawn group: GESAP counted 15 before the change and 3 after, on the same save. A new spawn added 3, and its wheels show as OtherNPC.

Retested with the grouping: a Chad Shuttle, whose main grid has decorative top parts, keeps its spawn data, and so do the rover bodies; their wheels show as OtherNPC. Same after a reload.

@Blaylock1988

Copy link
Copy Markdown
Contributor Author

GetGroup(Mechanical) can't help in GridsSpawned, because no top part has attached yet when it runs, so every grid is still alone in its group. But each rotor, hinge, piston and suspension already holds the ID of the top it's about to attach (TopBlockId, which the prefab spawn remaps along with the top). So now it only skips a grid if one of its top parts belongs to a base on another grid. Decorative tops have no base pointing at them, so their grid keeps the NpcData. Separate grids like the dropship's vehicles on connectors or landing gear still get their own.

@Blaylock1988

Copy link
Copy Markdown
Contributor Author

closing as agreed to in discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant