Skip to content

Setup Custom Input Bindings for SteamVR Input System

ChengNan Yang edited this page Nov 4, 2019 · 5 revisions
  • Step 1. Add new action set and actions in SteamVR Input window

    • After creating custom action set and actions, remember to Save and generate

      custombinding1

  • Step 2. Bind custom action to controller

    • Click on Open Binding UI(Sometimes the page is blank) or go to SteamVR(top-left corner)>Devices>Controller Settings

    • Bind myaction to Trigger

      custombinding2 custombinding3 custombinding4

  • Step 3. (METHOD 1) Create new action script

    • For SteamVR Plugin v2.0.1, this version is quite buggy
      • MUST add SteamVR_Behaviour.cs and SteamVR_ActivateActionSetOnLoad.cs custombinding5
using UnityEngine;
using Valve.VR;

public class MyActionScript : MonoBehaviour
{
    public SteamVR_Action_Boolean myAction;
    public SteamVR_Input_Sources handType;

    void Update()
    {
        Debug.Log("Value GetState:" + myAction.GetState(handType));
        Debug.Log("Value GetStateUp:" + myAction.GetStateUp(handType));
        Debug.Log("Value GetStateDown:" + myAction.GetStateDown(handType));
    }
}
  • Step 3. (METHOD 2) Create new action script
    • For SteamVR Plugin v2.1.0 and above
      • MUST add SteamVR_ActivateActionSetOnLoad.cs custombinding6
using UnityEngine;
using Valve.VR;

public class MyActionScript : MonoBehaviour
{
    public SteamVR_Action_Boolean myAction;
    public SteamVR_Input_Sources handType;

    void Start()
    {
        myAction.AddOnStateDownListener(TriggerDown, handType);
        myAction.AddOnStateUpListener(TriggerUp, handType);
    }

    public void TriggerUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
    {
        //TODO
    }

    public void TriggerDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
    {
        //TODO
    }

    void Update()
    {
        Debug.Log("Value GetState:" + myAction.GetState(handType));
        Debug.Log("Value GetStateUp:" + myAction.GetStateUp(handType));
        Debug.Log("Value GetStateDown:" + myAction.GetStateDown(handType));
    }
}