@@ -112,6 +112,7 @@ public bool IsEphysLinkControlled
112112 private set
113113 {
114114 ManipulatorBehaviorController . enabled = value ;
115+ print ( "MBC enabled: " + ManipulatorBehaviorController . enabled ) ;
115116 EphysLinkControlChangeEvent . Invoke ( ) ;
116117 EphysLinkControlledProbesChangedEvent . Invoke ( Instances . Where ( manager => manager . IsEphysLinkControlled ) . ToHashSet ( ) ) ;
117118 }
@@ -209,16 +210,15 @@ private void Start()
209210 /// </summary>
210211 public void Destroy ( )
211212 {
212-
213213 ProbeProperties . ReturnColor ( Color ) ;
214214
215215 ColliderManager . RemoveProbeColliderInstances ( _probeColliders ) ;
216216
217217 // Force disable Ephys Link
218218 if ( IsEphysLinkControlled )
219219 {
220- CommunicationManager . Instance . UnregisterManipulator ( ManipulatorBehaviorController . ManipulatorID ) ;
221220 IsEphysLinkControlled = false ;
221+ CommunicationManager . Instance . UnregisterManipulator ( ManipulatorBehaviorController . ManipulatorID ) ;
222222 }
223223
224224 // Delete this gameObject
@@ -228,10 +228,18 @@ public void Destroy()
228228
229229 private void OnDestroy ( )
230230 {
231+ // Destroy instance
231232 Debug . Log ( $ "Destroying probe: { name } ") ;
232233
233- Instances . Remove ( this ) ;
234- ProbeInsertion . Instances . Remove ( ProbeController . Insertion ) ;
234+ if ( ProbeInsertion . Instances . Count == 1 )
235+ ProbeInsertion . Instances . Clear ( ) ;
236+ else
237+ ProbeInsertion . Instances . Remove ( ProbeController . Insertion ) ;
238+
239+ if ( Instances . Count == 1 )
240+ Instances . Clear ( ) ;
241+ else
242+ Instances . Remove ( this ) ;
235243 }
236244
237245 private void OnEnable ( ) => Instances . Add ( this ) ;
0 commit comments