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

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:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class InvertLook : MonoBehaviour
{
 
    public InputActionAsset inputActionAsset; //In the Unity Editor, drag the action map asset from the project folders into this slot
    public InputAction lookAction; //Need this to refer to an action that is on the action amp asset
    public InputActionReference lookActionRef; //Need to establish a reference to the action
 
    // Start is called before the first frame update
    void Start()
    {
        lookAction = inputActionAsset.FindActionMap("Player").FindAction("Look");
    
        //How to make the reference 'connection' between lookActionRef (immediately below) to lookAction (immediately above)?
    
        lookActionRef.action.ApplyBindingOverride(new InputBinding {overrideProcessors = "invertVector2(invertX=false,invertY=false)" });
    }
 
}

After I posted this question I found another thread on it here , so I’m linking this to that.

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?

Sorry to Necro, but here is the code you can use for anyone who needs it in the future.

using UnityEngine.InputSystem;

private InputAction _action;
private InputActionReference _actionRef;

private void CreateActionReference()
{
    _actionRef = InputActionReference.Create(_action);
}
1 Like