Skip to content

Fix hatch attachNodeId auto-detection polluting shared internal prefabs#532

Closed
kilfoil wants to merge 2 commits into
FirstPersonKSP:mainfrom
kilfoil:fix/hatch-attachnode-shared-prefab-pollution
Closed

Fix hatch attachNodeId auto-detection polluting shared internal prefabs#532
kilfoil wants to merge 2 commits into
FirstPersonKSP:mainfrom
kilfoil:fix/hatch-attachnode-shared-prefab-pollution

Conversation

@kilfoil

@kilfoil kilfoil commented Jul 5, 2026

Copy link
Copy Markdown

Problem

When multiple parts share the same INTERNAL, OnLoad_Finalize() calls GetPartPrefabForInternal() which returns only the first part registered for that internal. Attach-node auto-detection runs against that part's nodes and writes the result directly onto the shared prop prefab (e.g. hatch.attachNodeId = "airlock").

Every subsequent part that clones the same prefab inherits that attachNodeId — even if the part has completely different (or no) attach nodes. This produces a logged error for every affected part on every flight load:

[ERR] [FreeIva] INTERNAL 'crewCabinInternals' contains PROP 'FreeIva_Hatch_Square'
      with attachNodeId 'airlock' but it was not found in PART 'USILS.Greenhouse.Inline'

GetPartPrefabForInternal() already logs a warning when multiple parts share an internal, but the auto-detection still proceeds with the wrong part and corrupts the prefab for all others.

Root cause

The detection runs at prefab-load time in InternalModuleFreeIva.OnLoad_Finalize(), where only one representative part is available. The result is written to a shared prop component, so all instances of that prop — regardless of which part they belong to — see the same attachNodeId.

Fix

Remove the attach-node auto-detection from OnLoad_Finalize() and move it into FreeIvaHatch.OnAwake(), which runs per flight instance with this.part being the actual instantiated part. Each part now detects its own nearest attach node independently against its own nodes.

InternalModuleFreeIva.x_partToInternalSpace is made internal so Hatch.cs can access the shared coordinate-space constant without duplication.

Test case

Place a vessel containing both a stock Mk1 Crew Cabin and a USI-LS Greenhouse Inline (both use crewCabinInternals). The ERR log entry for the greenhouse should no longer appear, and the crew cabin's airlock hatch should continue to function normally.

@kilfoil kilfoil marked this pull request as draft July 5, 2026 01:40
kilfoil and others added 2 commits July 4, 2026 23:24
When multiple parts share the same INTERNAL, OnLoad_Finalize() picked
only the first one via GetPartPrefabForInternal() and ran attach-node
auto-detection against its nodes, writing the result (e.g. 'airlock')
directly onto the shared prop prefab. Every subsequent part that cloned
that prefab inherited the wrong attachNodeId.

Symptoms: parts that reuse a stock internal as a placeholder (e.g.
USILS.Greenhouse.Inline using crewCabinInternals) log an ERR on every
flight load because their attach nodes don't include the one that was
auto-detected for the canonical part.

Fix: remove the prefab-time auto-detection from OnLoad_Finalize() and
move it into FreeIvaHatch.OnAwake(), which runs per flight instance
against the actual part. Each part now detects its own nearest attach
node independently, so shared internals work correctly for all parts
that use them.
OnLoad_Finalize() called GetPartPrefabForInternal() to auto-detect which
airlock transform to associate with each EVA hatch. That returns only the
FIRST part registered for a given internal, so its airlockName was written
into the shared prefab and inherited by every other part sharing the same
internal (e.g. USILS.Greenhouse.Inline, sspx-observation-25-1, and
Kosntruction.Workshop.250 all inherit crewCabinInternals' "Airlock" name
even though those parts have no such transform).

Move airlock auto-detection to Hatch.OnAwake(), where this.part is the
actual flight instance, applying the same spatial matching logic as before
but only for that specific hatch instance.

Also remove explicit airlockName = Airlock from docking port HatchConfigs:
those ports add FreeIva/Parts/Airlock to their model to provide an EVA
exit, but FindAirlock can't locate the transform by name (likely because
the instantiated model root gets "(Clone)" appended by Unity). The fallback
to part.airlock correctly finds the tagged transform already, so the named
lookup was just generating noise.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kilfoil kilfoil force-pushed the fix/hatch-attachnode-shared-prefab-pollution branch from 3943b22 to ec2076b Compare July 5, 2026 02:24
@JonnyOThan

Copy link
Copy Markdown
Collaborator

Doing it at load time is far more efficient. This isn’t the right fix.

@JonnyOThan JonnyOThan closed this Jul 5, 2026
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.

2 participants