Class InputActionAsset | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Class InputActionAsset

    An asset containing action maps and control schemes.

    Inheritance
    System.Object
    InputActionAsset
    Namespace: UnityEngine.Experimental.Input
    Syntax
    public class InputActionAsset : ScriptableObject, ICloneable, IInputActionCollection, IEnumerable<InputAction>
    Remarks

    Usually imported from JSON using .

    Be aware that input action assets do not separate between static data and dynamic (instance) data. For audio, for example, represents the static, shared data portion of audio playback whereas represents the dynamic, per-instance audio playback portion (referencing the clip through .

    For input, such a split is less beneficial as the same input is generally not exercised multiple times in parallel. Keeping both static and dynamic data together simplifies using the system.

    However, there are scenarios where you indeed want to take the same input action and exercise it multiple times in parallel. A prominent example of such a use case is local multiplayer where each player gets the same set of actions but is controlling them with a different device (or devices) each. This is easily achieved by simply instantiating the input action asset multiple times.

    Note also that all action maps in an asset share binding state. This means that if one map in an asset has to resolve its bindings, all maps in the asset have to.

    Fields

    kExtension

    Declaration
    public const string kExtension = "inputactions"
    Field Value
    Type Description
    System.String

    Properties

    actionMaps

    List of action maps defined in the asset.

    Declaration
    public ReadOnlyArray<InputActionMap> actionMaps { get; }
    Property Value
    Type Description
    ReadOnlyArray<InputActionMap>

    bindingMask

    Optional mask applied to all bindings in the collection.

    Declaration
    public InputBinding? bindingMask { get; set; }
    Property Value
    Type Description
    System.Nullable<InputBinding>
    Implements
    IInputActionCollection.bindingMask
    Remarks

    If this is not null, only bindings that match the mask will be used.

    controlSchemes

    List of control schemes defined in the asset.

    Declaration
    public ReadOnlyArray<InputControlScheme> controlSchemes { get; }
    Property Value
    Type Description
    ReadOnlyArray<InputControlScheme>
    Implements
    IInputActionCollection.controlSchemes

    devices

    Devices to use with the actions in this collection.

    Declaration
    public ReadOnlyArray<InputDevice>? devices { get; set; }
    Property Value
    Type Description
    System.Nullable<ReadOnlyArray<InputDevice>>
    Implements
    IInputActionCollection.devices
    Remarks

    If this is set, actions in the collection will exclusively bind to devices in the given list. For example, if two gamepads are present in the system yet only one gamepad is listed here, then a "<Gamepad>/leftStick" binding will only bind to the gamepad in the list and not to the one that is only available globally.

    Methods

    AddActionMap(InputActionMap)

    Add an action map to the asset.

    Declaration
    public void AddActionMap(InputActionMap map)
    Parameters
    Type Name Description
    InputActionMap map

    A named action map.

    AddControlScheme(InputControlScheme)

    Declaration
    public void AddControlScheme(InputControlScheme controlScheme)
    Parameters
    Type Name Description
    InputControlScheme controlScheme

    Clone()

    Duplicate the asset.

    Declaration
    public InputActionAsset Clone()
    Returns
    Type Description
    InputActionAsset

    A new asset that contains a duplicate of all action maps and actions in the asset.

    Remarks

    Unlike calling , cloning an asset will not duplicate data such as unique id and id.

    Contains(InputAction)

    Declaration
    public bool Contains(InputAction action)
    Parameters
    Type Name Description
    InputAction action
    Returns
    Type Description
    System.Boolean
    Implements
    IInputActionCollection.Contains(InputAction)

    Disable()

    Declaration
    public void Disable()
    Implements
    IInputActionCollection.Disable()

    Enable()

    Declaration
    public void Enable()
    Implements
    IInputActionCollection.Enable()

    FindAction(String)

    Find an InputAction by its name in of of the InputActionMap in the asset.

    Declaration
    public InputAction FindAction(string name)
    Parameters
    Type Name Description
    System.String name

    Name of the action as either a "map/action" combination (e.g. "gameplay/fire") or a simple name. In the former case, the name is split at the '/' slash and the first part is used to find a map with that name and the second part is used to find an action with that name inside the map. In the latter case, all maps are searched in order and the first action that has the given name in any of the maps is returned. Note that name comparisons are case-insensitive.

    Returns
    Type Description
    InputAction

    The action with the corresponding name or null if no matching action could be found.

    Remarks

    Does not allocate.

    Examples
    var asset = ScriptableObject.CreateInstance<InputActionAsset>();
    
    var map1 = new InputActionMap("map1");
    var map2 = new InputActionMap("map2");
    
    asset.AddActionMap(map1);
    asset.AddActionMap(map2);
    
    var action1 = map1.AddAction("action1");
    var action2 = map1.AddAction("action2");
    var action3 = map2.AddAction("action3");
    
    // Search all maps in the asset for any action that has the given name.
    asset.FindAction("action1") // Returns action1.
    asset.FindAction("action2") // Returns action2
    asset.FindAction("action3") // Returns action3.
    
    // Search for a specific action in a specific map.
    asset.FindAction("map1/action1") // Returns action1.
    asset.FindAction("map2/action2") // Returns action2.
    asset.FindAction("map3/action3") // Returns action3.

    GetActionMap(Guid)

    Declaration
    public InputActionMap GetActionMap(Guid id)
    Parameters
    Type Name Description
    Guid id
    Returns
    Type Description
    InputActionMap

    GetActionMap(String)

    Declaration
    public InputActionMap GetActionMap(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    InputActionMap

    GetControlScheme(String)

    Declaration
    public InputControlScheme GetControlScheme(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    InputControlScheme

    GetControlSchemeIndex(String)

    Declaration
    public int GetControlSchemeIndex(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    System.Int32

    GetEnumerator()

    Declaration
    public IEnumerator<InputAction> GetEnumerator()
    Returns
    Type Description
    IEnumerator<InputAction>

    LoadFromJson(String)

    Replace the contents of the asset with the data in the given JSON string.

    Declaration
    public void LoadFromJson(string json)
    Parameters
    Type Name Description
    System.String json

    RemoveActionMap(String)

    Declaration
    public void RemoveActionMap(string name)
    Parameters
    Type Name Description
    System.String name

    RemoveActionMap(InputActionMap)

    Declaration
    public void RemoveActionMap(InputActionMap map)
    Parameters
    Type Name Description
    InputActionMap map

    RemoveControlScheme(String)

    Declaration
    public void RemoveControlScheme(string name)
    Parameters
    Type Name Description
    System.String name

    ToJson()

    Return a JSON representation of the asset.

    Declaration
    public string ToJson()
    Returns
    Type Description
    System.String

    A string in JSON format that represents the static/configuration data present in the asset.

    Remarks

    This will not save dynamic execution state such as callbacks installed on InputAction or enabled/disabled states of individual maps and actions.

    Use LoadFromJson(String) to deserialize the JSON data back into an InputActionAsset.

    TryGetActionMap(Guid)

    Declaration
    public InputActionMap TryGetActionMap(Guid id)
    Parameters
    Type Name Description
    Guid id
    Returns
    Type Description
    InputActionMap

    TryGetActionMap(String)

    Declaration
    public InputActionMap TryGetActionMap(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    InputActionMap

    TryGetControlScheme(String)

    Declaration
    public InputControlScheme? TryGetControlScheme(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    System.Nullable<InputControlScheme>

    TryGetControlSchemeIndex(String)

    Declaration
    public int TryGetControlSchemeIndex(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    System.Int32
    Back to top Copyright © 2015-2018 Unity
    Generated by DocFX