-
Notifications
You must be signed in to change notification settings - Fork 4.3k
InputActuatorComponent to allow the generation of an action space from an InputActionAsset #4881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 71 commits
6ef9ebb
9c0dcde
7bcdb0d
a60e9b0
2e9da14
2911655
f235c38
fdf8dc8
2a8194f
e37cba0
372f38f
1ded6ec
6d1608f
9dccd8f
e0187e6
da26c1f
27139b4
f2326ad
5c0b29d
cd31e47
422971c
451ff5a
d22c0fa
ba8fa87
3c0633b
7857460
c5267c5
33c52c4
4eced60
20a8570
46afb84
d5c27fa
288f5d1
0483eed
d4787da
709626a
493ed8d
f7e812d
a6d4355
f95b96a
071eba9
b025f9b
c4fb132
9fe4db3
c990d55
3966dec
3aa206c
83a420b
5cde583
9089f1f
1dfc0b2
3d9a627
95cadd4
739c407
6da565e
e9c9e77
3155f45
26d74f1
d0ebd0c
fb433c5
9e65a9a
aa9ff02
040d393
0c09254
8b352d4
35731c6
2554765
3af71ad
27a9c55
5142ac8
2208128
a385b95
6687ebb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"m_Name": "Settings", | ||
"m_Path": "ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json", | ||
"m_Dictionary": { | ||
"m_DictionaryValues": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Integration of the Input System Package with ML-Agents | ||
|
||
## Overview | ||
One area we are always trying to improve is getting developers up and running with ML-Agents. With this in mind, | ||
we have implemented an `InputActuatorComponent` that sets up an action space for your `Agent` based on | ||
an `InputActionAsset` that is referenced by the `IInputActionAssetProvider` interface, or the `PlayerInput` component | ||
surfnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
that may be living on your player controlled `Agent`. This means that if you have code outside of your agent that | ||
handles input, you will not need to implement the Heuristic function in agent as well. The `InputActuatorComponent` | ||
will handle this for you. You can now train and run inference on `Agents` with an action space defined by an `InputActionAsset`. | ||
|
||
This implementation includes: | ||
|
||
* C# `InputActuatorComponent` you can attach to your Agent. | ||
* Implement the `IInputActionAssetProvider` in the `Componenet` where you handle player input. | ||
* An example environment where the input handling code is not in the Heuristic function of the Agent subclass. | ||
|
||
### Feedback | ||
We have only implemented a small subset of `InputControl` types that we thought would cover a large portion of what | ||
most developers would use. Please let us know if you want more control types implemented by posting in the [ML-Agents | ||
forum.](https://forum.unity.com/forums/ml-agents.453/) | ||
|
||
We would also like your feedback on the workflow of integrating this into your games. If you run | ||
into workflow issues please let us know in the ML-Agents forums, or if you've discovered a bug, | ||
please file a bug on our GitHub page. | ||
|
||
## Getting started | ||
The C# code for the `InputActuatorComponent` exists inside of the extensions package (com.unity.ml-agents.extensions). A good first step would be to familiarize with the extensions package by reading the document [here](com.unity.ml-agents.extensions.md). The second step would be to take a look at how we have implemented the C# code in the example Input Integration scene (located under ML-Agents-Input-Example/Assets/ML-Agents/Examples/PushBlock/). Once you have some familiarity, then the next step would be to add the InputActuatorComponent to your player Agent. The example we have implemented uses C# Events to send information from the Input System. | ||
|
||
Additionally, see below for additional technical specifications on the C# code for the InputActuatorComponent. | ||
|
||
## Technical specifications for the InputActuatorComponent | ||
|
||
### `IInputActionsAssetProvider` Interface | ||
The `InputActuatorComponent` searches for a `Component` that implements | ||
`IInputActionAssetProvider` on the `GameObject` they both are attached to. It is important to note | ||
that if multiple `Components` on your `GameObject` need to access an `InputActionAsset` to handle events, | ||
they will need to share the same instance of the `InputActionAsset` that is returned from the | ||
`IInputActionAssetProvider`. | ||
|
||
### `InputActuatorComponent` class | ||
The `InputActuatorComponent` is the bridge between ML-Agents and the Input System.. It allows ML-Agents to | ||
* create an `ActionSpec` for your Agent based on an `InputActionAsset` that comes from an | ||
`IInputActionAssetProvider`. | ||
* send simulated input from a training process or a neural network | ||
* let developers keep their input handling code in one place | ||
|
||
This is accomplished by adding the `InputActuatorComponenet` to an Agent which already has the PlayerInput component attached. | ||
surfnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Setting up a scene using the `InputActuatorComponent` | ||
1. Add the `com.unity.inputsystem` version 1.1.0-preview.3 or later to your project via the Package Manager window. | ||
2. If you have already setup an InputActionAsset skip to Step 3, otherwise follow these sub steps: | ||
1. Create an InputActionAsset to allow your Agent to be controlled by the Input System. | ||
2. Handle the events from the Input System where you normally would (i.e. a script external to your Agent class). | ||
3. Add the InputSystemActuatorComponent to the GameObject that has the `PlayerInput` and `Agent` components attached. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER | ||
using Unity.MLAgents.Extensions.Input; | ||
using UnityEditor; | ||
|
||
namespace Unity.MLAgents.Extensions.Editor.Input | ||
{ | ||
[CustomEditor(typeof(InputActuatorComponent))] | ||
internal class InputActuatorComponentEditor : UnityEditor.Editor | ||
{ | ||
const string k_ActionSpecName = "m_ActionSpec"; | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
var so = serializedObject; | ||
so.Update(); | ||
InputActuatorComponent o = so.targetObject as InputActuatorComponent; | ||
_ = o.ActionSpec; | ||
EditorGUI.indentLevel++; | ||
EditorGUI.BeginDisabledGroup(true); | ||
surfnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EditorGUILayout.PropertyField(so.FindProperty(k_ActionSpecName)); | ||
EditorGUI.EndDisabledGroup(); | ||
EditorGUI.indentLevel--; | ||
} | ||
} | ||
} | ||
#endif // MLA_INPUT_SYSTEM && UNITY_2019_OR_NEWER |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "Unity.ML-Agents.Extensions.Editor.Input", | ||
"references": [ | ||
"Unity.ML-Agents", | ||
"Unity.ML-Agents.Extensions.Input", | ||
"Unity.ML-Agents.Editor", | ||
"Unity.InputSystem" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [ | ||
{ | ||
"name": "com.unity.inputsystem", | ||
"expression": "1.1.0-preview", | ||
"define": "MLA_INPUT_SYSTEM" | ||
} | ||
], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.