Skip to content

Commit ffaf8fd

Browse files
authored
Merge pull request #204 from De-Panther/null_reference_interactables
Fixed null reference errors when destroying contacted interactables
2 parents 9742d60 + 5237130 commit ffaf8fd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Null reference errors when destroying contacted interactables.
11+
912
## [0.14.0] - 2021-12-26
1013
### Added
1114
- Support for AR headsets in SceneHitTest.

Packages/webxr-interactions/Runtime/Scripts/ControllerInteraction.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,15 @@ private Rigidbody GetNearestRigidBody()
528528
Rigidbody nearestRigidBody = null;
529529
float minDistance = float.MaxValue;
530530
float distance = 0.0f;
531+
bool removeNulls = false;
531532

532533
foreach (Rigidbody contactBody in contactRigidBodies)
533534
{
535+
if (contactBody == null)
536+
{
537+
removeNulls = true;
538+
continue;
539+
}
534540
distance = (contactBody.gameObject.transform.position - transform.position).sqrMagnitude;
535541

536542
if (distance < minDistance)
@@ -540,6 +546,11 @@ private Rigidbody GetNearestRigidBody()
540546
}
541547
}
542548

549+
if (removeNulls)
550+
{
551+
contactRigidBodies.RemoveAll(x => x == null);
552+
}
553+
543554
return nearestRigidBody;
544555
}
545556
}

0 commit comments

Comments
 (0)