An asset containing action maps and control schemes.
Inheritance
System.Object
InputActionAsset
public class InputActionAsset : ScriptableObject, IInputActionCollection, IEnumerable<InputAction>, IEnumerable
Fields
Declaration
public const string Extension = "inputactions"
Field Value
Type |
Description |
System.String |
|
Properties
List of action maps defined in the asset.
Declaration
public ReadOnlyArray<InputActionMap> actionMaps { get; }
Property Value
Optional mask applied to all bindings in the collection.
Declaration
public InputBinding? bindingMask { get; set; }
Property Value
Implements
List of control schemes defined in the asset.
Declaration
public ReadOnlyArray<InputControlScheme> controlSchemes { get; }
Property Value
Implements
Devices to use with the actions in this collection.
Declaration
public ReadOnlyArray<InputDevice>? devices { get; set; }
Property Value
Implements
True if any action in the asset is currently enabled.
Declaration
public bool enabled { get; }
Property Value
Type |
Description |
System.Boolean |
|
Declaration
public InputAction this[string actionNameOrId] { get; }
Parameters
Type |
Name |
Description |
System.String |
actionNameOrId |
|
Property Value
Methods
Add an action map to the asset.
Declaration
public void AddActionMap(InputActionMap map)
Parameters
Exceptions
Type |
Condition |
System.ArgumentNullException |
map is null .
|
System.InvalidOperationException |
map has no name or asset already contains a
map with the same name.
|
Declaration
public void AddControlScheme(InputControlScheme controlScheme)
Parameters
Declaration
public bool Contains(InputAction action)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Implements
Declaration
Implements
Declaration
Implements
Declaration
public InputAction FindAction(string actionNameOrId)
Parameters
Type |
Name |
Description |
System.String |
actionNameOrId |
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.
Alternatively, the given string can be a GUID as given by id.
|
Returns
Type |
Description |
InputAction |
The action with the corresponding name or null if no matching action could be found.
|
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");
asset.FindAction("action1")
asset.FindAction("action2")
asset.FindAction("action3")
asset.FindAction("map1/action1")
asset.FindAction("map2/action2")
asset.FindAction("map3/action3")
Search by unique action ID.
asset.FindAction(action1.id.ToString())
asset.FindAction(action2.id.ToString())
asset.FindAction(action3.id.ToString())
Exceptions
Type |
Condition |
System.ArgumentNullException |
actionNameOrId is null or empty.
|
Declaration
public static InputActionAsset FromJson(string json)
Parameters
Type |
Name |
Description |
System.String |
json |
|
Returns
Declaration
public InputActionMap GetActionMap(Guid id)
Parameters
Type |
Name |
Description |
System.Guid |
id |
|
Returns
Declaration
public InputActionMap GetActionMap(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Declaration
public InputControlScheme GetControlScheme(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Declaration
public int GetControlSchemeIndex(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Int32 |
|
Declaration
public IEnumerator<InputAction> GetEnumerator()
Returns
Type |
Description |
System.Collections.Generic.IEnumerator<InputAction> |
|
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 |
|
Declaration
public void RemoveActionMap(string nameOrId)
Parameters
Type |
Name |
Description |
System.String |
nameOrId |
|
Declaration
public void RemoveActionMap(InputActionMap map)
Parameters
Declaration
public void RemoveControlScheme(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Return a JSON representation of the asset.
Declaration
Returns
Type |
Description |
System.String |
A string in JSON format that represents the static/configuration data present
in the asset.
|
Declaration
public InputAction TryGetAction(Guid guid)
Parameters
Type |
Name |
Description |
System.Guid |
guid |
|
Returns
Declaration
public InputActionMap TryGetActionMap(Guid id)
Parameters
Type |
Name |
Description |
System.Guid |
id |
|
Returns
Declaration
public InputActionMap TryGetActionMap(string nameOrId)
Parameters
Type |
Name |
Description |
System.String |
nameOrId |
|
Returns
Declaration
public InputControlScheme? TryGetControlScheme(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Declaration
public int TryGetControlSchemeIndex(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Int32 |
|
Extension Methods
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.