docs.unity3d.com
    Show / Hide Table of Contents

    Class InputActionReference

    References a specific InputAction in an InputActionMap stored inside an InputActionAsset.

    Inheritance
    Object
    InputActionReference
    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 null in which case the reference is reset to its default state which does not reference an action.

    Returns
    Type Description
    InputActionReference

    A new InputActionReference referencing action.

    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 null in which case the reference is reset to its default state which does not reference an action.

    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 asset (see actionMaps). Case-insensitive.

    String actionName

    Name of the action in mapName. Case-insensitive.

    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 reference. Can be null.

    See Also

    InputActionProperty
    InputAction
    InputActionAsset
    In This Article
    • Properties
      • action
      • asset
    • Methods
      • Create(InputAction)
      • Set(InputAction)
      • Set(InputActionAsset, String, String)
      • ToInputAction()
      • ToString()
    • Operators
      • Implicit(InputActionReference to InputAction)
    • See Also
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023