Search Unity

Question Steam VR Error With Action Set

Discussion in 'VR' started by MarbleDrop, Jul 20, 2021.

  1. MarbleDrop

    MarbleDrop

    Joined:
    Jul 19, 2021
    Posts:
    3
    NullReferenceException: Object reference not set to an instance of an object
    Valve.VR.SteamVR_Action_Boolean.GetState (Valve.VR.SteamVR_Input_Sources inputSource) (at Assets/SteamVR/Input/SteamVR_Action_Boolean.cs:94)
    VRController.CalculateMovement () (at Assets/Scripts/VRController.cs:58)
    VRController.Update () (at Assets/Scripts/VRController.cs:35)

    That's the error I get when I try to run my game.

    It seems to be linking lines from my controller input script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Valve.VR;
    5.  
    6. public class VRController : MonoBehaviour
    7. {
    8.     public float m_Sensitivity = 0.1f;
    9.     public float m_MaxSpeed = 1.0f;
    10.  
    11.     public SteamVR_Action_Boolean m_MovePress = null;
    12.     public SteamVR_Action_Vector2 m_MoveValue = null;
    13.  
    14.     private float m_Speed = 0.0f;
    15.  
    16.     private CharacterController m_CharacterController = null;
    17.     private Transform m_XRRig = null;
    18.     private Transform m_Head = null;
    19.  
    20.     public bool pause = false;
    21.  
    22.     private void Awake()
    23.     {
    24.         m_CharacterController = GetComponent<CharacterController>();
    25.     }
    26.     private void Start()
    27.     {
    28.         m_XRRig = SteamVR_Render.Top().origin;
    29.         m_Head = SteamVR_Render.Top().head;
    30.     }
    31.     private void Update()
    32.     {
    33.         HandleHead();
    34.         HandleHeight();
    35.         CalculateMovement();
    36.     }
    37.     private void HandleHead()
    38.     {
    39.         // Store current
    40.         Vector3 oldPosition = m_XRRig.position;
    41.         Quaternion oldRotation = m_XRRig.rotation;
    42.  
    43.         // Rotation
    44.         transform.eulerAngles = new Vector3(0.0f, m_Head.rotation.eulerAngles.y, 0.0f);
    45.  
    46.         // Restore
    47.         m_XRRig.position = oldPosition;
    48.         m_XRRig.rotation = oldRotation;
    49.     }
    50.     private void CalculateMovement()
    51.     {
    52.         // Movement Orientation
    53.         Vector3 orientationEuler = new Vector3(0, transform.eulerAngles.y, 0);
    54.         Quaternion orientation = Quaternion.Euler(orientationEuler);
    55.         Vector3 movement = Vector3.zero;
    56.  
    57.         // If Not Moving
    58.         if (m_MovePress.GetState(SteamVR_Input_Sources.Any))
    59.         {
    60.             m_Speed = 0;
    61.         }
    62.  
    63.         // If Button Pressed
    64.         if (m_MovePress.state)
    65.         {
    66.             // Add, Clamp
    67.             m_Speed += m_MoveValue.axis.y * m_Sensitivity;
    68.             m_Speed = Mathf.Clamp(m_Speed, -m_MaxSpeed, m_MaxSpeed);
    69.  
    70.             //Orientation
    71.             movement += orientation * (m_Speed * Vector3.forward) * Time.deltaTime;
    72.         }
    73.  
    74.         // Apply
    75.         m_CharacterController.Move(movement);
    76.     }
    77.     private void HandleHeight()
    78.     {
    79.         // Get Head in Local Space
    80.         float headHeight = Mathf.Clamp(m_Head.localPosition.y, 1, 2);
    81.         m_CharacterController.height = headHeight;
    82.  
    83.         //Cut in Half
    84.         Vector3 newCenter = Vector3.zero;
    85.         newCenter.y = m_CharacterController.height / 2;
    86.         newCenter.y += m_CharacterController.skinWidth;
    87.  
    88.         // Move Capsule in Local Space
    89.         newCenter.x = m_Head.localPosition.x;
    90.         newCenter.z = m_Head.localPosition.z;
    91.  
    92.         //Rotate
    93.         newCenter = Quaternion.Euler(0, -transform.eulerAngles.y, 0) * newCenter;
    94.  
    95.         //Apply
    96.         m_CharacterController.center = newCenter;
    97.     }
    98. }
    Any Help With this issue is appreciated!
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    Due to the SteamVR plugin is developed and maintained by Valve, please post your issues on their Github so their team can address.