Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

New Input System - How to make InputActionReference refer to Input Action

Discussion in 'Input System' started by JeffreyBennett, Sep 6, 2022.

  1. JeffreyBennett

    JeffreyBennett

    Joined:
    May 18, 2017
    Posts:
    23
    How do I make an InputActionReference variable actually establish a reference to an InputAction variable?

    I want to override processors on bindings on input actions, but I cannot find the way to construct the reference (yes, I've been looking at the documentation for InputActionReference InputAction and Processors in the documents.

    I do have the Input Action Asset (referred to as an action map) created in the editor (You know, that box that pops up when you double-click the action map in your project files? It has three columns, Action Maps, Actions, and Properties, and you set up the bindings on the actions by using Listen and hitting a key. Yeah, that thing).

    I can see that I have no way in my current code to point the reference to the action, and I DO get a Null Reference Exception: Object reference not set to an instance of an object, and I expect that. I just can't figure out how to complete the reference.

    Am I supposed to drag something in the editor? Is there a getSomething line of code I should be using? Am I going about this entirely incorrectly? Is there not a way to do this until a future version comes out? Is there NEVER gonna be a way to do this?

    What's the trick?

    Here's my code at the moment:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class InvertLook : MonoBehaviour
    7. {
    8.  
    9.     public InputActionAsset inputActionAsset; //In the Unity Editor, drag the action map asset from the project folders into this slot
    10.     public InputAction lookAction; //Need this to refer to an action that is on the action amp asset
    11.     public InputActionReference lookActionRef; //Need to establish a reference to the action
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         lookAction = inputActionAsset.FindActionMap("Player").FindAction("Look");
    17.    
    18.         //How to make the reference 'connection' between lookActionRef (immediately below) to lookAction (immediately above)?
    19.    
    20.         lookActionRef.action.ApplyBindingOverride(new InputBinding {overrideProcessors = "invertVector2(invertX=false,invertY=false)" });
    21.     }
    22.  
    23. }
     
    Last edited: Sep 6, 2022
  2. JeffreyBennett

    JeffreyBennett

    Joined:
    May 18, 2017
    Posts:
    23
    After I posted this question I found another thread on it here, so I'm linking this to that.
     
  3. TheAverageHuman

    TheAverageHuman

    Joined:
    Dec 16, 2021
    Posts:
    2
    Does anybody have the code (Just the code and a simple and in-depth explanation of what it does) to change an inputAction to an inputActionReference?