Skip to content

Commit

Permalink
Instead of relying on Unity serialization (which doesn't work here) s…
Browse files Browse the repository at this point in the history
…etup `config` in `Start`. `OnLoad` is also not called when placing parts in the editor.
  • Loading branch information
dkavolis committed Sep 6, 2022
1 parent 49e0ece commit ba7de8b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

namespace FerramAerospaceResearch.FARPartGeometry
{
[Serializable]
internal struct GeometryPartModuleConfig
{
public bool forceUseColliders;
Expand Down Expand Up @@ -112,7 +111,7 @@ public class GeometryPartModule : PartModule, IRescalable<GeometryPartModule>
private int _sendUpdateTick;
private int _meshesToUpdate = -1;

[SerializeField] private GeometryPartModuleConfig config = new();
private GeometryPartModuleConfig config = new();

public bool HasCrossSectionAdjusters
{
Expand Down Expand Up @@ -216,6 +215,10 @@ private void Start()
{
destroyed = false;

GeometryPartModule modulePrefab = part.partInfo.partPrefab.FindModuleImplementing<GeometryPartModule>();
if (modulePrefab is not null)
config = modulePrefab.config;

//RebuildAllMeshData();
SetupIGeometryUpdaters();
SetupICrossSectionAdjusters();
Expand Down Expand Up @@ -1046,16 +1049,9 @@ public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);

// Flight passes node from the craft config which is empty, using the loaded prefab instead
if (HighLogic.LoadedSceneIsFlight)
{
// Flight passes node from the craft config which is empty, use the loaded prefab instead
GeometryPartModule modulePrefab = part.partInfo.partPrefab.FindModuleImplementing<GeometryPartModule>();
if (modulePrefab is not null)
{
config = modulePrefab.config;
return;
}
}
return;

LoadBool(node, "forceUseColliders", ref config.forceUseColliders);
LoadBool(node, "forceUseMeshes", ref config.forceUseMeshes);
Expand Down

0 comments on commit ba7de8b

Please sign in to comment.