I am having SteamVR input issues.

I have followed this tutorial and filled in some basic code to check if it is working. I so far have this

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class gun : MonoBehaviour
{
    public SteamVR_Action_Boolean Shoot;
    public GameObject pistol;
    public SteamVR_Input_Sources handType;


    // Start is called before the first frame update
    void Start()
    {
        Shoot.AddOnStateDownListener(TriggerDown, handType);
        Shoot.AddOnStateUpListener(TriggerUp, handType);
        Debug.Log("start");
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void TriggerDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
    {
        Debug.Log("Trigger is down");
    }
    public void TriggerUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
    {
        Debug.Log("Trigger is up");
    }
}

However, I cannot get a response from any button presses. I have double checked my controller is working so I figure it has to be my code breaking. Just to be safe here’s this as well.(also this is like my third time submitting this question because I’m having issues with the website) alt text alt text

My guess is that you forgot to add something in the Inspector, or in the input setup in Window->SteamVR Input.

I use Unity 2019.2, it may be that something have changed in later versions, for example there is a “new input system” in 2021. And the latest SteamVR version may cause problems for both the tutorial and the way below.


If you don’t get that tutorial to work, there is another way to do it more directly by sampling the input state every frame.

Make sure to use the default action set. And add bindings for ‘Throttle’ and ‘Fire’ in the steamvr setup.

//run in Update()
if ((SteamVR_Actions.default_Throttle.GetAxis(SteamVR_Input_Sources.LeftHand) > 0.5f)
    || SteamVR_Actions.default_Fire.GetState(SteamVR_Input_Sources.LeftHand))
{
    iLeftHanded = 1;
}
//example for gamepad
if ((SteamVR_Actions.default_Throttle.GetAxis(SteamVR_Input_Sources.Gamepad) > 0.5f)
    || SteamVR_Actions.default_Fire.GetState(SteamVR_Input_Sources.Gamepad))
{
    iLeftHanded = 0;
}

Now 2 images (my SteamVR is in Swedish, but you will get an idea)