Resource:Interior Cell Navcut Bug

Overview
Interior workshops like Diamond City Player Home, Vault 88, and Sim Settlement's Chapter 2's HQ impact the NPC pathing of every other interior cell in the game. Things you build in an interior workshop will block pathing in all other cells if the coordinates of things happen to intersect areas NPCs are meant to walk.

For example, if you build a bed in one cell at coordinate 0/0/0, all other interior cells with a navmesh near 0/0/0 will have a bed shaped hole cut in them.

Technical Details
When building things inside a settlement, the navmesh is dynamically adjusted to cut a hole where that item exists. We call this navcutting, it's generally awesome as it allows NPCs to path somewhat believably around what you build.

It does so by taking the bounding box of the mesh, and forcing the navmesh that intersects it to reform a new shape around that bounding box.

This is a unique feature of locations flagged as having a Workshop. If we dynamically spawn in items not associated with a workshop, or in cells and locations not designated as part of a workshop, the navcutting does not occur. Or at least it's not supposed to.

It turns out that with Interior cells, this rule is sort of broken.

Interior workshops, such as the Diamond City Player home, Vault 88, or our HQ cells all have the workshop tag to allow them to dynamically alter navmesh, and it generally works. The problem is that it appears to impact every single other interior cell, both other workshop cells, and non-workshop cells.

The bounding box for each built item is now cutting navmesh across all interior cells.

Fortunately, Bethesda seems to not always center their interior locations at the 0/0/0 coordinates, so the problem isn't noticeable in every single cell, since oftentimes, those navcutting bounding boxes won't be anywhere near the navmesh in other cells, but in some cases it can be quite brutal - even blocking NPCs from getting to important spots for quests to continue.

This is the Bethesda code for dynamic navcutting: if ( Workshop::WorkshopCanScrapRef(this, v6, v7) || Workshop::WorkshopCanCreateRef(0i64, this, v22) ) {             v52 = FLOAT_1_0; TESObjectREFR::GetOrientation(this, (struct NiMatrix3 *)v48); v23 = *((_DWORD *)this + 53); v49 = *((_DWORD *)this + 52); v24 = *((_DWORD *)this + 54); v50 = v23; v51 = v24; v25 = TESObjectREFR::GetScale(this); v26 = *(_QWORD *)this; v52 = v25; v27 = (int *)(*(__int64 (__fastcall **)(TESObjectREFR *, char *))(v26 + 1176))(this, v60); v53 = *v27; v54 = v27[1]; v28 = v27[2]; v29 = *(_QWORD *)this; v55 = v28; v30 = (int *)(*(__int64 (__fastcall **)(TESObjectREFR *, char *))(v29 + 1184))(this, v59); v31 = *((_DWORD *)this + 5); v56 = *v30; v57 = v30[1]; v58 = v30[2]; DynamicNavmesh::SetPrecutActivation(               (DynamicNavmesh *)`BSTSingletonSDMBase>>::QInstancePtr'::`2'::pinstanceS,                v31,                (struct BSNavmeshMath::OrientedBoundingBox *)v48,                v2); }

Test Case
If you would like to try replicating this yourself to see it in action:


 * 1) 1. Take a companion with you to Vault 111 back past your spouse's pod and up the short stairs, you should be able to direct your companion to walk around on that small raised area.
 * 2) 2. Now go heavily build up the area around the red door in the Diamond City Player Home, really cover up as much as you can around that section of the place.
 * 3) 3. Return to that spot in Vault 111, and notice your companion probably won't be able to go up those stairs anymore, and definitely won't be able to path up to that area as cleanly as they did before the building.

Known Issues

 * The interior cell "worldspace" is limited in size, the max cell dimensions are -32767 to 32768.
 * With each navcut being universally located across all interior cells in the base game/DLC/Creation Club as well as mod added locations each interior (all sources) needs to occupy a unique set of spatial coordinates. Even if the mod author community coordinates efforts there is a "bin stacking problem" wherein all official and mod added content must be packed into the finite interior cell size without overlap as efficiently as possible.
 * Breaking NPC pathing can break quests if NPC's cannot travel to trigger boxes, markers, etc.
 * Even if a mod author moves their interior content away from the 0/0/0 coordinates in hopes of reducing conflict, many objects will remain persistent to their original location if updated in the same save game that has previously loaded that interior. A new save game would be required for the update to apply.
 * Due to the power grid scrap crash bug power lines can only be moved with F4SE functions. Other power related objects should be safe to move to new coordinates.

Speculations

 * Navcuts may have a large or infinite Z (height) component. One mod author has reported pathing dead zones intersecting at the same X,Y coordinates at multiple levels on the Z axis. If true this would further compound the problem of trying to fit multiple interiors into a finite space. Kinggath did not find Z related dead zones in his testing of the bug. More testing is needed to confirm if this is actually an issue.

Resources

 * F4SE fix: EngineFixesF4 by Snapdragon2/Dewey. It will be available with the Concord Restoration Project: Phase II by Niston for beta testing and will then most likely be rolled into the Workshop Framework dll by Kinggath.
 * xEdit script to export the navmesh bounds of cells in bulk by Pra.
 * xEdit script to offset interior cell references by Pra
 * "Offset Interior Cell Refs.pas" must be run on a single cell. It shows a UI with 3 inputs for X/Y/Z and a target file dropdown. It will then offset all references and navmesh vertices within this cell by the given amounts. Either in-place or as overrides in another file, depending on the selection in the target file dropdown.
 * xEdit script to export interior cell bounds by Pra
 * "Export Interior Cell Bounds.pas" can be run on a several cells, and it will generate a CSV with bounds for each, based on all references and navmesh vertices. Optionally also with intersections, but only from within the current run. Has a UI with checkboxes. Check the intersections box to view all cells which will intersect with your workshop cell to determine potential conflicts.
 * xEdit script to export interior cell to a worldspace by Pra.

Work in Progress

 * Pra and others are looking into xEdit scripts to allow for automated movement of interior content to new coordinates as a short term solution. Done see Resources
 * F4SE authors are looking into a script extender engine level fix. F4SE fix is now available, see Resources. However this will not benefit console players.
 * Pra is looking into how to autogenerate a worldspace from an interior cell Done see Resources
 * Testing by Tenhats so far indicates that exterior workshops do not impact other exterior worldspaces as interior workshops impact other interior worldspaces. Testing still needs to be done to see if interior workshops impact exterior worldspaces.