diff --git a/Assets/VRTK/SDK/Simulator/SDK_SimController.cs b/Assets/VRTK/SDK/Simulator/SDK_SimController.cs
index d8e33148b..57e028a9d 100644
--- a/Assets/VRTK/SDK/Simulator/SDK_SimController.cs
+++ b/Assets/VRTK/SDK/Simulator/SDK_SimController.cs
@@ -127,6 +127,7 @@ public override uint GetControllerIndex(GameObject controller)
/// The GameObject of the controller
public override GameObject GetControllerByIndex(uint index, bool actual = false)
{
+ SetupPlayer();
VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
switch (index)
{
@@ -146,7 +147,7 @@ public override GameObject GetControllerByIndex(uint index, bool actual = false)
/// A Transform containing the origin of the controller.
public override Transform GetControllerOrigin(VRTK_ControllerReference controllerReference)
{
- return controllerReference.actual.transform;
+ return (controllerReference != null && controllerReference.actual != null ? controllerReference.actual.transform : null);
}
///
@@ -326,6 +327,7 @@ public override SDK_ControllerHapticModifiers GetHapticModifiers()
/// A Vector3 containing the current velocity of the tracked object.
public override Vector3 GetVelocity(VRTK_ControllerReference controllerReference)
{
+ SetupPlayer();
uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
switch (index)
{
@@ -345,6 +347,7 @@ public override Vector3 GetVelocity(VRTK_ControllerReference controllerReference
/// A Vector3 containing the current angular velocity of the tracked object.
public override Vector3 GetAngularVelocity(VRTK_ControllerReference controllerReference)
{
+ SetupPlayer();
uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
switch (index)
{
@@ -423,11 +426,19 @@ public override bool GetControllerButtonState(ButtonTypes buttonType, ButtonPres
protected virtual void OnEnable()
{
- GameObject simPlayer = SDK_InputSimulator.FindInScene();
- if (simPlayer != null)
+ SetupPlayer();
+ }
+
+ protected virtual void SetupPlayer()
+ {
+ if (rightController == null || leftController == null)
{
- rightController = simPlayer.transform.Find(RIGHT_HAND_CONTROLLER_NAME).GetComponent();
- leftController = simPlayer.transform.Find(LEFT_HAND_CONTROLLER_NAME).GetComponent();
+ GameObject simPlayer = SDK_InputSimulator.FindInScene();
+ if (simPlayer != null)
+ {
+ rightController = (rightController == null ? simPlayer.transform.Find(RIGHT_HAND_CONTROLLER_NAME).GetComponent() : rightController);
+ leftController = (leftController == null ? simPlayer.transform.Find(LEFT_HAND_CONTROLLER_NAME).GetComponent() : leftController);
+ }
}
}
@@ -521,6 +532,7 @@ protected virtual bool GetControllerButtonState(uint index, string keyMapping, B
/// Returns true if the button is being pressed.
protected virtual bool IsButtonPressed(uint index, ButtonPressTypes type, KeyCode button)
{
+ SetupPlayer();
if (index >= uint.MaxValue)
{
return false;
@@ -528,14 +540,14 @@ protected virtual bool IsButtonPressed(uint index, ButtonPressTypes type, KeyCod
if (index == 1)
{
- if (rightController != null && !rightController.Selected)
+ if (!rightController.Selected)
{
return false;
}
}
else if (index == 2)
{
- if (leftController != null && !leftController.Selected)
+ if (!leftController.Selected)
{
return false;
}