@@ -204,14 +204,20 @@ private void Awake()
204204 // store the root's animator
205205 animator = VisualsRoot . GetComponent < Animator > ( ) ;
206206
207+ if ( animator == null )
208+ {
209+ Debug . LogError ( "Hand rig does not have an animator. Disabling gameObject" ) ;
210+ gameObject . SetActive ( false ) ;
211+ }
212+
207213 // hide visuals by default
208214 if ( VisualsRoot != null )
209215 {
210216 VisualsRoot . SetActive ( false ) ;
211217 }
212218 }
213219
214- public void OnEnable ( )
220+ private void OnEnable ( )
215221 {
216222 // When component is enabled, start up the timer logic if auto activate is specified
217223 if ( AutoActivate )
@@ -220,7 +226,7 @@ public void OnEnable()
220226 }
221227 }
222228
223- public void OnDisable ( )
229+ private void OnDisable ( )
224230 {
225231 // Stop all logic when the component is disabled, even if not using auto activate
226232 if ( loopRunning )
@@ -317,7 +323,10 @@ private IEnumerator HintLoopSequence(string stateToPlay)
317323
318324 // show the root
319325 SetActive ( VisualsRoot , true ) ;
320- animator . Play ( stateToPlay ) ;
326+ if ( animator != null )
327+ {
328+ animator . Play ( stateToPlay ) ;
329+ }
321330
322331 float visibleTime = Time . time ;
323332 int playCount = 0 ;
@@ -343,7 +352,10 @@ private IEnumerator HintLoopSequence(string stateToPlay)
343352 {
344353 yield return new WaitForSeconds ( RepeatDelay ) ;
345354 SetActive ( VisualsRoot , true ) ;
346- animator . Play ( stateToPlay ) ;
355+ if ( animator != null )
356+ {
357+ animator . Play ( stateToPlay ) ;
358+ }
347359 visibleTime = Time . time ;
348360 playCount ++ ;
349361 }
@@ -359,7 +371,7 @@ private void SetActive(GameObject root, bool show)
359371 {
360372 root . SetActive ( show ) ;
361373
362- if ( show )
374+ if ( show && animator != null )
363375 {
364376 animator . Play ( fadeInAnimationState ) ;
365377 }
@@ -371,12 +383,15 @@ private void SetActive(GameObject root, bool show)
371383 /// </summary>
372384 public float GetAnimationDuration ( string animationStateName )
373385 {
374- RuntimeAnimatorController ac = animator . runtimeAnimatorController ;
375- for ( int i = 0 ; i < ac . animationClips . Length ; i ++ )
386+ if ( animator != null )
376387 {
377- if ( ac . animationClips [ i ] . name . StartsWith ( animationStateName ) )
388+ RuntimeAnimatorController ac = animator . runtimeAnimatorController ;
389+ for ( int i = 0 ; i < ac . animationClips . Length ; i ++ )
378390 {
379- return ac . animationClips [ i ] . length ;
391+ if ( ac . animationClips [ i ] . name . StartsWith ( animationStateName ) )
392+ {
393+ return ac . animationClips [ i ] . length ;
394+ }
380395 }
381396 }
382397
@@ -406,7 +421,7 @@ private bool ShouldHideVisuals()
406421 /// Return true if either of the user's hands are being tracked.
407422 /// Return false if neither of the user's hands are being tracked.
408423 /// </summary>
409- bool IsHandTracked ( )
424+ private bool IsHandTracked ( )
410425 {
411426 return HandJointUtils . FindHand ( Handedness . Right ) != null || HandJointUtils . FindHand ( Handedness . Left ) != null ;
412427 }
0 commit comments