Skip to content

Commit bcf03d6

Browse files
committed
fix(Presence): fix crash on object grab if no collider is present
The Player Presence script checks to see if a grabbed object has a collider so it can ignore collisions with grabbed objects. However, if the grabbed object doesn't have a collider but it's children do then it would crash. This fix prevents that and checks for child colliders to remove the physics collisions from.
1 parent 09abdc6 commit bcf03d6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_PlayerPresence.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ private void InitHeadsetListeners()
4747

4848
private void OnGrabObject(object sender, ObjectInteractEventArgs e)
4949
{
50-
Physics.IgnoreCollision(this.GetComponent<Collider>(), e.target.GetComponent<Collider>(), true);
50+
if(e.target.GetComponent<Collider>())
51+
{
52+
Physics.IgnoreCollision(this.GetComponent<Collider>(), e.target.GetComponent<Collider>(), true);
53+
}
54+
55+
foreach(var childCollider in e.target.GetComponentsInChildren<Collider>())
56+
{
57+
Physics.IgnoreCollision(this.GetComponent<Collider>(), childCollider, true);
58+
}
5159
}
5260

5361
private void OnUngrabObject(object sender, ObjectInteractEventArgs e)

Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_TouchpadWalking.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using System.Collections;
55

6+
[RequireComponent(typeof(VRTK_PlayerPresence))]
67
public class VRTK_TouchpadWalking : MonoBehaviour
78
{
89
[SerializeField]

0 commit comments

Comments
 (0)