File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -23,16 +23,34 @@ public override void OnLoad(ConfigNode node)
23
23
if ( followTransform == null || followTransform . name != transformName )
24
24
{
25
25
if ( transformName != null ) followTransform = part . FindModelTransform ( transformName ) ;
26
- if ( followTransform == null ) Debug . LogError ( $ "[{ MODULENAME } ] transformName was empty or does not exist.") ;
27
- this . isEnabled = followTransform != null ;
28
- this . enabled = followTransform != null ;
26
+ if ( followTransform == null ) Debug . LogError ( $ "[{ MODULENAME } ] transformName '{ transformName } ' was empty or does not exist.") ;
29
27
}
28
+
29
+ if ( followTransform == null )
30
+ {
31
+ // this may be important if someone is swapping out versions of this module with B9PS
32
+ part . CoPOffset = Vector3 . zero ;
33
+ }
34
+
35
+ // NOTE: isEnabled will be persisted to the save file, but we want to treat it purely as runtime state
36
+ this . isEnabled = followTransform != null ;
37
+ this . enabled = followTransform != null && HighLogic . LoadedSceneIsFlight ;
30
38
}
31
39
32
40
public void FixedUpdate ( )
33
41
{
34
- if ( ! HighLogic . LoadedSceneIsFlight ) return ;
35
- if ( followTransform != null ) part . CoPOffset = part . transform . InverseTransformPoint ( followTransform . position ) ;
42
+ // Note that we shouldn't ever get here if the transform just didn't exist
43
+ // But it's certainly possible for *something* to delete it later
44
+ if ( followTransform == null )
45
+ {
46
+ isEnabled = false ;
47
+ enabled = false ;
48
+ // should we reset CoPOffset here? Not sure.
49
+ }
50
+ else
51
+ {
52
+ part . CoPOffset = part . transform . InverseTransformPoint ( followTransform . position ) ;
53
+ }
36
54
}
37
55
}
38
56
}
You can’t perform that action at this time.
0 commit comments