@@ -469,14 +469,11 @@ public SpherePointerQueryInfo(int bufferSize, float radius, float angle, float m
469
469
470
470
public bool HasValidGrabbable ( Vector3 pointerPosition , Vector3 pointerAxis , bool ignoreCollidersNotInFOV , LRUCache < int , NearInteractionGrabbable > componentCache )
471
471
{
472
- Vector3 grabbablePosition = pointerPosition ;
473
- NearInteractionGrabbable currentGrabbable = null ;
474
-
475
472
for ( int i = 0 ; i < numColliders ; i ++ )
476
473
{
477
474
Collider collider = queryBuffer [ i ] ;
478
- if ( IsColliderValidGrabbable ( collider , ignoreCollidersNotInFOV , out currentGrabbable , componentCache )
479
- && IsColliderPositionValid ( collider , pointerPosition , pointerAxis , queryAngle , queryMinDistance , out grabbablePosition ) )
475
+ if ( IsColliderValidGrabbable ( collider , ignoreCollidersNotInFOV , out NearInteractionGrabbable currentGrabbable , componentCache )
476
+ && IsColliderPositionValid ( collider , pointerPosition , pointerAxis , queryAngle , queryMinDistance , out _ ) )
480
477
{
481
478
if ( currentGrabbable != null )
482
479
{
@@ -584,17 +581,23 @@ public void TryUpdateQueryBufferForLayerMask(LayerMask layerMask, Vector3 pointe
584
581
public bool IsColliderValidGrabbable ( Collider collider , bool ignoreCollidersNotInFOV , out NearInteractionGrabbable currentGrabbable , LRUCache < int , NearInteractionGrabbable > componentCache )
585
582
{
586
583
// Check if the collider has a grabbable component which is valid
584
+ bool isValidGrabbable = true ;
587
585
int instanceId = collider . gameObject . GetInstanceID ( ) ;
588
586
if ( ! componentCache . TryGetValue ( instanceId , out currentGrabbable ) )
589
587
{
590
- currentGrabbable = collider . gameObject . GetComponent < NearInteractionGrabbable > ( ) ;
588
+ #if UNITY_2019_4_OR_NEWER
589
+ isValidGrabbable &= collider . TryGetComponent ( out currentGrabbable ) ;
590
+ #else
591
+ currentGrabbable = collider . GetComponent < NearInteractionGrabbable > ( ) ;
592
+ #endif
591
593
if ( currentGrabbable != null )
592
594
{
593
595
componentCache . Add ( instanceId , currentGrabbable ) ;
594
596
}
595
597
}
596
598
597
- bool isValidGrabbable = ( currentGrabbable != null ) && ! ( ignoreBoundsHandlesForQuery && currentGrabbable . IsBoundsHandles ) ;
599
+ isValidGrabbable &= ( currentGrabbable != null ) && ! ( ignoreBoundsHandlesForQuery && currentGrabbable . IsBoundsHandles ) ;
600
+
598
601
if ( ! isValidGrabbable )
599
602
{
600
603
// Remove it from the cache if the grabbable is no longer valid for the object
0 commit comments