-
Notifications
You must be signed in to change notification settings - Fork 4.3k
API for sending custom protobuf messages to and from Unity. #1595
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
Merged
vincentpierre
merged 18 commits into
Unity-Technologies:develop
from
malmaud:custom_protos
Mar 28, 2019
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d3f9fd6
Merge pull request #1588 from Unity-Technologies/hotfix-0.6.0a
vincentpierre e3b86a2
Merge pull request #1764 from Unity-Technologies/release-v0.7
vincentpierre b2000da
API for sending custom protobuf messages to and from Unity.
malmaud 17b680c
Rename custom_output to custom_outputs.
malmaud daebc0d
Move custom protos to their own files.
malmaud 32c9945
Add SetCustomOutput method.
malmaud 12c99c2
Add docstrings.
malmaud b6383eb
Various adjustments.
malmaud 60ca7bb
Remove custom action result.
malmaud 515a69a
Remove custom action result from Python API
malmaud 1405af4
Start new documentation.
malmaud 85a073f
Add some docstrings
malmaud e691701
Expand documentation.
malmaud 6f4a3ad
Typos
malmaud 3cf307a
Tweak doc.
malmaud 36e933e
Fix typo.
malmaud d9d987a
Clarify docs.
malmaud d0c137b
Remove trailing whitspace
malmaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Clarify docs.
- Loading branch information
commit d9d987abacd33cf8addbfd43c7f5cdd016536ef3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Creating custom protobuffer messages | ||
# Creating custom protobuf messages | ||
|
||
Unity and Python communicate by sending protobuffer messages to and from each other. You can create custom protobuffer messages if you want to exchange structured data beyond what is included by default. | ||
Unity and Python communicate by sending protobuf messages to and from each other. You can create custom protobuf messages if you want to exchange structured data beyond what is included by default. | ||
|
||
Whenever you change the fields of a custom message, you must run `protobuf-definitions/make.bat` to create C# and Python files corresponding to the new message. Follow the directions in that file for guidance. After running it, reinstall the Python package by running `pip install ml-agents` and make sure your Unity project is using the newly-generated version of `UnitySDK`. | ||
Assume the ml-agents repository is checked out to a folder named $MLAGENTS_ROOT. Whenever you change the fields of a custom message, you must run `$MLAGENTS_ROOT/protobuf-definitions/make.bat` to create C# and Python files corresponding to the new message. Follow the directions in that file for guidance. After running it, reinstall the Python package by running `pip install $MLAGENTS_ROOT/ml-agents` and make sure your Unity project is using the newly-generated version of `$MLAGENTS_ROOT/UnitySDK`. | ||
|
||
## Custom message types | ||
|
||
|
@@ -34,8 +34,8 @@ message CustomAction { | |
enum Direction { | ||
NORTH=0; | ||
SOUTH=1; | ||
EAST=1; | ||
WEST=1; | ||
EAST=2; | ||
WEST=3; | ||
} | ||
float walkAmount = 1; | ||
Direction direction = 2; | ||
|
@@ -46,7 +46,7 @@ In your Python file, create an instance of a custom action: | |
|
||
```python | ||
from mlagents.envs.communicator_objects import CustomAction | ||
env = mlagents.UnityEnvironment(...) | ||
env = mlagents.envs.UnityEnvironment(...) | ||
... | ||
action = CustomAction(direction=CustomAction.NORTH, walkAmount=2.0) | ||
env.step(custom_action=action) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to also provide a regular action along with the custom one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't, the default is a zero array. |
||
|
@@ -78,7 +78,7 @@ Note that the protobuffer compiler automatically configures the capitalization s | |
|
||
By default, you can configure an environment `env ` in the Python API by specifying a `config` parameter that is a dictionary mapping strings to floats. | ||
|
||
You can also configure an environment using a custom protobuf message. To do so, add fields to the `CustomResetParameters` protobuffer message in `custom_reset_parameters.proto`, analogously to `CustomAction` above. Then pass an instance of the message to `env.reset` via the `custom_reset_parameters` keyword parameter. | ||
You can also configure an environment using a custom protobuf message. To do so, add fields to the `CustomResetParameters` protobuf message in `custom_reset_parameters.proto`, analogously to `CustomAction` above. Then pass an instance of the message to `env.reset` via the `custom_reset_parameters` keyword parameter. | ||
|
||
In Unity, you can then access the `customResetParameters` field of your academy to accesss the values set in your Python script. | ||
|
||
|
@@ -137,7 +137,7 @@ env.reset(custom_reset_parameters=params) | |
|
||
By default, Unity returns observations to Python in the form of a floating-point vector. | ||
|
||
You can define a custom observation message to supplement that. To do so, add fields to the `CustomObservation` protobuffer message in `custom_observation.proto`. | ||
You can define a custom observation message to supplement that. To do so, add fields to the `CustomObservation` protobuf message in `custom_observation.proto`. | ||
|
||
Then in your agent, create an instance of a custom observation via `new CommunicatorObjects.CustomObservation`. Then in `CollectObservations`, call `SetCustomObservation` with the custom observation instance as the parameter. | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.