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)
2323 if ( followTransform == null || followTransform . name != transformName )
2424 {
2525 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.") ;
2927 }
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 ;
3038 }
3139
3240 public void FixedUpdate ( )
3341 {
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+ }
3654 }
3755 }
3856}
You can’t perform that action at this time.
0 commit comments