@@ -74,14 +74,6 @@ protected override void Awake()
7474 base . Awake ( ) ;
7575
7676#if UNITY_WSA && UNITY_2017_2_OR_NEWER
77- foreach ( var sourceState in InteractionManager . GetCurrentReading ( ) )
78- {
79- if ( sourceState . source . kind == InteractionSourceKind . Controller )
80- {
81- StartTrackingController ( sourceState . source ) ;
82- }
83- }
84-
8577 Application . onBeforeRender += Application_onBeforeRender ;
8678
8779 if ( GLTFMaterial == null )
@@ -123,16 +115,29 @@ private void Application_onBeforeRender()
123115 {
124116 // NOTE: This work is being done here to present the most correct rendered location of the controller each frame.
125117 // Any app logic depending on the controller state should happen in Update() or using InteractionManager's events.
126- UpdateControllerState ( ) ;
118+ // We don't want to potentially start loading a new controller model in this call, since onBeforeRender shouldn't
119+ // do much work for performance reasons.
120+ UpdateControllerState ( false ) ;
127121 }
128122
129- private void UpdateControllerState ( )
123+ private void UpdateControllerState ( bool createNewControllerIfNeeded = true )
130124 {
131125#if UNITY_WSA && UNITY_2017_2_OR_NEWER
132126 foreach ( var sourceState in InteractionManager . GetCurrentReading ( ) )
133127 {
128+ if ( sourceState . source . kind != InteractionSourceKind . Controller )
129+ {
130+ continue ;
131+ }
132+
133+ string key = GenerateKey ( sourceState . source ) ;
134+ if ( createNewControllerIfNeeded && ! controllerDictionary . ContainsKey ( key ) && ! loadingControllers . Contains ( key ) )
135+ {
136+ StartTrackingController ( sourceState . source ) ;
137+ }
138+
134139 MotionControllerInfo currentController ;
135- if ( sourceState . source . kind == InteractionSourceKind . Controller && controllerDictionary . TryGetValue ( GenerateKey ( sourceState . source ) , out currentController ) )
140+ if ( controllerDictionary . TryGetValue ( key , out currentController ) )
136141 {
137142 if ( AnimateControllerModel )
138143 {
@@ -412,7 +417,7 @@ private void FinishControllerSetup(GameObject controllerModelGameObject, Interac
412417 {
413418 var parentGameObject = new GameObject
414419 {
415- name = handedness + "Controller"
420+ name = dictionaryKey + "Controller"
416421 } ;
417422
418423 parentGameObject . transform . parent = transform ;
0 commit comments