@@ -95,6 +95,8 @@ public override void OnStart(PartModule.StartState state)
9595
9696 GameEvents . onVesselWasModified . Add ( onVesselModified ) ;
9797 GameEvents . onPartCouple . Add ( onCouple ) ;
98+ GameEvents . onVesselCreate . Add ( onNewVessel ) ;
99+ GameEvents . onVesselSOIChanged . Add ( SOIChange ) ;
98100
99101 Transform l1 = part . FindModelTransform ( "SignalLight.004" ) ;
100102 Transform l2 = part . FindModelTransform ( "SignalLight.003" ) ;
@@ -155,6 +157,8 @@ protected override void OnDestroy()
155157
156158 GameEvents . onVesselWasModified . Remove ( onVesselModified ) ;
157159 GameEvents . onPartCouple . Remove ( onCouple ) ;
160+ GameEvents . onVesselCreate . Remove ( onNewVessel ) ;
161+ GameEvents . onVesselSOIChanged . Remove ( SOIChange ) ;
158162 }
159163
160164 private void onCouple ( GameEvents . FromToAction < Part , Part > p )
@@ -186,6 +190,37 @@ private IEnumerator waitOnVessel()
186190 DMSeismicHandler . Instance . addLoadedSeismometer ( part . flightID , this ) ;
187191 }
188192
193+ private void onNewVessel ( Vessel v )
194+ {
195+ if ( v == null )
196+ return ;
197+
198+ if ( ! v . loaded )
199+ return ;
200+
201+ if ( v != vessel )
202+ return ;
203+
204+ if ( values == null )
205+ return ;
206+
207+ values . VesselRef = v ;
208+ }
209+
210+ private void SOIChange ( GameEvents . HostedFromToAction < Vessel , CelestialBody > VB )
211+ {
212+ if ( VB . host == null )
213+ return ;
214+
215+ if ( ! VB . host . loaded )
216+ return ;
217+
218+ if ( VB . host != vessel )
219+ return ;
220+
221+ values = null ;
222+ }
223+
189224 private void onVesselModified ( Vessel v )
190225 {
191226 if ( v == null )
@@ -695,7 +730,7 @@ private bool rayImpact(bool b, Transform t, float s, float max, out float d)
695730 int i = 0 ; //Just to prevent this from getting stuck in a loop
696731 while ( hitT != null && i < 30 )
697732 {
698- if ( hitT . name . Contains ( vessel . mainBody . name ) )
733+ if ( hitT == vessel . mainBody . bodyTransform )
699734 {
700735 d = hit . distance ;
701736 return true ;
@@ -710,6 +745,8 @@ private bool rayImpact(bool b, Transform t, float s, float max, out float d)
710745
711746 private void getScienceData ( bool asteroid , bool silent , float score )
712747 {
748+ values . VesselRef = vessel ;
749+
713750 ScienceData data = DMSeismicHandler . makeData ( values , score , exp , experimentID , false , asteroid ) ;
714751
715752 if ( data == null )
0 commit comments