KSPModdingLibs / KSPCommunityFixes

Community patches for bugs in the KSP codebase
49 stars 17 forks source link

stock ModulePartVariants does not recreate part joints correctly when loading from a save file #179

Closed JonnyOThan closed 7 months ago

JonnyOThan commented 7 months ago

ModulePartVariants can alter attachnode positions. The most apparent example of this is the structural tubes from Making History.

When you first launch a craft file, the attachnode positions come directly from the craft file and are correct:

image

After reverting to launch, or saving and reloading the scene, etc. the attachnode positions are wrong. This causes the game to create the physics joints between parts in the wrong place:

image

Note that in this craft file, one "arm" has the "top" node connected at the center, and one has the "bottom" node connected at the center. That is, the tubes are pointed in the same direction. It's pretty clear that the bottom node isn't in the right place. This can be verified with the debugger or unityexplorer.

Craft file used above: ModulePartVariant-joints.zip

JonnyOThan commented 7 months ago

I can think of two approaches to fixing this, one general and one specific:

General solution: Alter how vessels in flight store their attachnodes to be more like how it's done in craft files. The position, rotation, and size of the node should be persisted. This should fix the problem for all modules that change attachnodes, though it may have unintended effects if some modules expect the nodes to be unmodified by the time they reach OnStart, etc. This also doesn't help with ships that are already in flight, and loading the old form of the data must still be supported.

Specific solution: Have ModulePartVariant move the attachnode somewhere in the start process. This seems congruent to how it works in the editor scene (although it shouldn't move child parts). This will work for ships in flight and might have a smaller surface area.