NPC Bug: Bots stand still because they get an unusable navmesh - 2 Different Causes - Full Analysis!

Erwin Heyms shared this bug 22 hours ago
Submitted

Bug tested in : Game version: 01.211.019 (experimental mode), single player.


SUMMARY

I'm currently writing some mods for SE1 involving NPC's and found that at times they refused to walk around. I'm using Claude to write these mods and was able to find the root cause of the issue. My mods do not change anything about the AI or Behaviour or the NPCs, it only determines where they spawn / respawn. So this pointed to a bug in their code and I found 2 such cases.


(1) A small grid next to a bigger grid, gets the bigger grid's navmesh;


(2) On a large tall grid (multi-manager mode) a whole deck is left outside the only patch that gets built.


As a result, NPC bots on player-built grids can stand completely still - no walking, no seats, no chasing, not even when attacked.


Because the navmesh they are given does not cover the spot they stand on, their path requests fail silently and nothing retries, so they stay frozen until something unrelated (moving a grid, a world reload) happens to give them a usable navmesh. At times it can generate multiple navmeshes, other times it only generates those in the wrong locations.


We found two separate causes, both in MyRDPathfinding (Sandbox.Game.AI.Pathfinding.RecastDetour):


1. Wrong grid.

GetNavigationArea picks a bot's navigation grid by the distance to each grid's world AABB, with ties going to the grid with more blocks. A small grid that lies inside a larger grid's (rotation-inflated) AABB therefore gets the larger grid's navmesh, and its bots can't walk.

Moving the larger grid away fixes it instantly.

30dc27a74f0a2ead5eb72210c251df9f


6419dea117e8dae7fa2c95d8ac320b9d


See GIF: Navmesh Overlapping Grids 2


2. Misplaced patch on large grids.

When a grid's navigation-aligned box is more than 400 m across or more than 70 m tall (the check at the top of CreateManager), it switches to multi-manager mode and builds 70 m tall patches snapped to fixed steps along the grid's up axis instead of around the requesting bot. On our station the snapping put the only patch one step above the spawn deck, so the whole deck lay outside it - but ContainsPosition still counted those bots as covered, so the patch that would cover them was never built. Measured: a frozen bot 44 m below the centre of the 70 m patch.


Spawning a bot one deck higher, or reloading with bots spread over several decks, sometimes makes it work.

33b396834648602fcbdb74febc5efb65

65ba86a8de492c69f8cc216046b9d8c0

See GIF: Navmesh - Single Grid for large station 2


Sometimes in this situatio navmeshes do generate correctly, because of random chance when the right NPC asks for a navmesh first, it does work


SEE THE CASE 2 FOLLOW UP - below.


30025227d128dbcd9aaf9813aadeef60


And GIF: Navmesh - Multi Grid for large station 2


Impact:

Any scenario, mod or server that places NPC crews on stations or next to other ships (encounters, NPC stations, crew mods) can end up with bots that look broken.


It is intermittent from the player's point of view, because it depends on grid placement and on which bot asks for a path first.


Evidence is in the game log:

Every new navmesh manager is logged with its centre and the requesting bot's distance from it ("... agent=<bot> at N m").


The details, log lines, measurements and suggested fixes for both cases follow below.


----------------------------------------------------------------------------------------------------------------------------


Game version: 01.211.019 (experimental mode), single player.


Bots are spawned by a mod with MyVisualScriptLogicProvider.SpawnBot and use the vanilla CombatBehavior / AstronautBehavior trees. Both problems also hit bots that are attacked: they don't move at all (no chase, no cover), so the AI does ask for paths - the paths fail.


How to see which navmesh a bot got: every new navmesh manager is logged as

"Navmesh manager created: area=... center=(x y z) forward=(...) ... tiles=AxBx16m height=H agent=<bot> at N m" N of 0-3 m = built around the bot; tens of metres = the bot got someone else's or a misplaced patch.


CASE 1 - small grid next to a bigger grid


What happens:

Bots standing on a small grid that lies close to a bigger grid never start walking: no seat, no wander, no terminal visit.

They start walking at once when one of the grids is moved away. Bots on a grid with no bigger grid nearby walk normally.


How to reproduce:


1. Park a small grid (here ~20 blocks, a test platform) next to a larger ship (here ~1250 blocks) so that the platform lies inside the ship's world bounding box (easy when the ship sits at an angle: its axis-aligned box is much larger than the hull).


2. Spawn a few bots on the small grid.


3. They stand still. The log shows the navmesh built around the ship, not around them:

"Navmesh manager created: area=MyDynamicGridNavigationArea center=(<the ship>) ... agent=<bot> at 51 m"


4. Fly the ship a few hundred metres away. The next log line is "Navmesh manager created: area=MyDynamicGridNavigationArea center=(<the platform>) ... agent=<bot> at 3 m"

and the bots start walking.


Cutting part of a grid off as a separate grid gives the same problem: the cut piece still lies inside the big grid's AABB.


Cause (from the game code):


MyRDPathfinding.GetNavigationArea(position) looks at every grid in a 500 m box around the bot and picks the grid whose WORLD AABB is closest to the bot (distance 0 when the bot is inside that AABB). Ties are broken by the larger BlocksCount. A bot standing on the small grid is inside both AABBs (distance 0 to both), so the bigger grid wins and the bot gets that grid's navigation area. Its paths are planned on the wrong grid and fail, so it never moves.


Suggested fix:


Prefer the grid the bot is actually standing on (the grid under its feet / its support grid, or the grid whose oriented bounding box contains the bot) before falling back to the AABB-distance rule; or compare distances against the grids' oriented boxes instead of their world AABBs, so a nearby rotated ship doesn't swallow small grids beside it.


CASE 2 - large grid (multi-manager mode): every bot on one deck stands still.


What happens:


On a large station (~29,000 blocks, one solid grid, no subgrids, no debris nearby) the log says "CreateManager grid exceeds cap, using multi-manager mode areaId=..."


"Navmesh manager created: area=MyDynamicGridNavigationArea center=(...) tiles=21x21x16m height=70 agent=<bot> at 45 m" and every bot on the spawn deck stands still - combat and peaceful bots, also when attacked. The same happens on a fresh paste of the station (again "at 45 m"). The same station sometimes works on another visit.


Evidence:


1. Despawning all bots and spawning them again at the same spots rebuilds the SAME wrong patch every time (three cycles in one session, identical centre (-62597.8 -149498.5 25756.2), "at 45 m", bots frozen each time).


2. Controlled test: with that one patch built, a bot spawned 13 blocks (32.5 m) HIGHER on the same station walked at once, while all bots on the spawn deck stayed frozen. No new navmesh manager was created for either.


3. After a world reload with the bots already standing all over the station, the game built THREE managers in the same frame:


center=(-62623.1 -149450.8 25689.9) ... agent at 43 m

center=(-62610.4 -149474.6 25723.0) ... agent at 10 m

center=(-62597.8 -149498.5 25756.2) ... agent at 17 m <- the only manager in every frozen visit.


The three centres lie on one line, 42.8 m apart, along the station's up axis (perpendicular to the logged forward 0.68 0.69 0.24).


The middle one covers the spawn deck (a bot 10 m from its centre); the frozen visits only ever got the one above it. With the lower manager present, every bot walked.


4. Measured on the pasted copy (again only one manager):


Navmesh manager created: center=(-63247.5 -149398.3 25937.9) forward=(0.68 0.69 0.24) tiles=21x21x16m height=70, agent at 45 m frozen bot at (-63267.9 -149379.7 25902.7); grid up (0.30 -0.56 0.78), grid forward (0.68 0.69 0.24) = the manager's forward offset from the manager centre along the grid axes: up -44.0 m, forward -9.5 m, sideways ~0 => the bot stands 44 m below the centre of a 70 m tall patch, about 9 m BELOW its bottom, yet no manager is built for it.


Likely cause (from the game code + the tests):


CreateManager uses one patch only when the grid's navigation-aligned box (GetNavAlignedOBB) is at most 400 m x 400 m across and 70 m tall (halfExtents.X*2 <= 400, halfExtents.Z*2 <= 400, halfExtents.Y*2 <= 70); otherwise it uses multi-manager mode.

So any grid taller than 70 m (28 large blocks) along its up axis is affected, however small its footprint.


In multi-manager mode MyRDPathfinding.CreateManager does not centre the patch on the requesting bot: GetAxisUnion / SnapCenterAlongAxis snap the centre to the grid's tile attice, so patches sit at fixed steps along the grid's up axis (42.8 m apart here), and each patch is only 70 m tall (ClampedTileHeight). For a bot on the spawn deck the snapping picks the patch one step ABOVE that deck, leaving the deck below its 70 m band.


Because the bot's position still counts as inside that manager (GetBestPathFromManagers -> ContainsPosition, a coarser volume than the generated mesh), no second manager is created for the deck, so none of its bots ever gets a usable navmesh. Which patches exist depends on where the first requesting bots stand, so the same station can work on one visit (bots spread over several decks, several patches) and not the next (bots woken one by

one on the spawn deck, one patch).


Suggested fix:


Make sure the snapped patch contains the requesting position with some vertical margin (pick the lattice step whose 70 m band contains the requester, or snap the height axis separately from the horizontal ones), and/or make ContainsPosition use the actual generated volume, so a bot outside it triggers a new manager.


FOLLOW-UP - CASE 2 seen in-game:

The deck's patch is missing when the bots freeze, and present when they walk.


To see the patches, we drew each "Navmesh manager created" box from the game log in the world as a see-through box (centre, forward, tiles x 16 m across, height 70 m, up = the grid's up). Each patch has its own colour: patch #1 red, patch #2 light blue.


The attached pictures and gif show the same pasted station (~22,500 blocks, one grid, no subgrids) after a plain world reload.


What the log shows on that reload (both lines in the same frame, 8 bots woken at once, spread over two decks):


CreateManager grid exceeds cap, using multi-manager mode areaId=142263211835121687

Navmesh manager created: center=(-63259.8 -149374.6 25905.2) forward=(0.68 0.69 0.24) tiles=21x21x16m height=70 agent at 10 m <- #1 red

CreateManager grid exceeds cap, using multi-manager mode areaId=142263211835121687

Navmesh manager created: center=(-63247.3 -149398.2 25938.0) forward=(0.68 0.69 0.24) tiles=21x21x16m height=70 agent at 16 m <- #2 blue


What this adds to CASE 2:


1. Patch positions are fixed per grid.

Patch #2 is the same patch as in the frozen visit measured in evidence 4 (center=(-63247.5 -149398.3 25937.9)) - same centre within 0.2 m, same forward, same size.

2. The patches are stacked 42.5 m apart along the grid's up axis (grid up 0.30 -0.56 0.78), each 70 m tall, so neighbours overlap by about 27 m. Same pattern as on the original station (42.8 m).

3. The spawn deck lies inside patch #1 only. A bot on that deck (logged once a second) stands 1.5 m below the centre of #1 and 43.8 m below the centre of #2 - i.e. below the bottom of #2, the only patch built in every frozen visit.

4. With #1 present, the same bot on the same deck walks normally (2-4 m/s, over stairs and slopes), where in the frozen visits it never moved. Nothing else changed: same grid, same deck, same bots.


Conclusion:

The bots on the spawn deck freeze exactly when the patch that covers their deck (#1) is not built and they are served the patch one step above (#2) instead.

When a bot on another deck makes the game build #2 and a spawn-deck bot makes it build #1, everything works.


Open question for the developers:


In the frozen visits the spawn-deck bot itself was the requester ("agent at 45 m") and still got #2, although the lattice step closest to it is #1 (1.5 m away).

So the step chosen for a request is not simply the one nearest the requester - it may depend on request order, on the managers that already exist, or on how SnapCenterAlongAxis / GetAxisUnion pick the step.


The fix suggested above (choose the step whose 70 m band contains the requester, and let ContainsPosition use the real patch volume so an uncovered bot triggers a new manager) would cover both cases.

Leave a Comment
 
Attach a file