Class InputActionReference
References a specific InputAction in an InputActionMap stored inside an InputActionAsset.
Namespace: UnityEngine.InputSystem
Syntax
public class InputActionReference : ScriptableObject
Remarks
The difference to a plain reference directly to an InputAction object is that an InputActionReference can be serialized without causing the referenced InputAction to be serialized as well. The reference will remain intact even if the action or the map that contains the action is renamed.
References can be set up graphically in the editor by dropping individual actions from the project browser onto a reference field.
Properties
action
The action that the reference resolves to. Null if the action cannot be found.
Declaration
public InputAction action { get; }
Property Value
Type | Description |
---|---|
InputAction | The action that reference points to. |
Remarks
Actions are resolved on demand based on their internally stored IDs.
asset
The asset that the referenced action is part of. Null if the reference is not initialized or if the asset has been deleted.
Declaration
public InputActionAsset asset { get; }
Property Value
Type | Description |
---|---|
InputActionAsset | InputActionAsset of the referenced action. |
Methods
Create(InputAction)
Create a new InputActionReference object that references the given action.
Declaration
public static InputActionReference Create(InputAction action)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An input action. Must be contained in an InputActionMap
that is itself contained in an InputActionAsset. Can be |
Returns
Type | Description |
---|---|
InputActionReference | A new InputActionReference referencing |
Set(InputAction)
Initialize the reference to refer to the given action.
Declaration
public void Set(InputAction action)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An input action. Must be contained in an InputActionMap
that is itself contained in an InputActionAsset. Can be |
Set(InputActionAsset, String, String)
Look up an action in the given asset and initialize the reference to point to it.
Declaration
public void Set(InputActionAsset asset, string mapName, string actionName)
Parameters
Type | Name | Description |
---|---|---|
InputActionAsset | asset | An .inputactions asset. |
String | mapName | Name of the InputActionMap in |
String | actionName | Name of the action in |
ToInputAction()
Declaration
public InputAction ToInputAction()
Returns
Type | Description |
---|---|
InputAction |
ToString()
Return a string representation of the reference useful for debugging.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A string representation of the reference. |
Operators
Implicit(InputActionReference to InputAction)
Convert an InputActionReference to the InputAction it points to.
Declaration
public static implicit operator InputAction(InputActionReference reference)
Parameters
Type | Name | Description |
---|---|---|
InputActionReference | reference | An InputActionReference object. Can be null. |
Returns
Type | Description |
---|---|
InputAction | The value of action from |