Skip to content

Commit a4baab2

Browse files
Release v0.7 disable gRPC on non supported platforms (#1743)
* Fix for GRPC, need documentation * Edits * typo * Fixes * Missing typo * Modified the documentation * Updated the documentation
1 parent 930b051 commit a4baab2

File tree

5 files changed

+115
-4
lines changed

5 files changed

+115
-4
lines changed

UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta

Lines changed: 78 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Generated by the protocol buffer compiler. DO NOT EDIT!
33
// source: mlagents/envs/communicator_objects/unity_to_external.proto
44
// </auto-generated>
5+
6+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
7+
58
#pragma warning disable 1591
69
#region Designer generated code
710

@@ -128,3 +131,6 @@ protected override UnityToExternalClient NewInstance(ClientBaseConfiguration con
128131
}
129132
}
130133
#endregion
134+
135+
#endif
136+

UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
12
using Grpc.Core;
3+
#endif
24
using System.IO;
35
using System.Threading;
46
using System.Threading.Tasks;
@@ -16,9 +18,10 @@ public class RPCCommunicator : Communicator
1618
/// If true, the communication is active.
1719
bool m_isOpen;
1820

21+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
1922
/// The Unity to External client.
2023
UnityToExternal.UnityToExternalClient m_client;
21-
24+
#endif
2225
/// The communicator parameters sent at construction
2326
CommunicatorParameters m_communicatorParameters;
2427

@@ -41,6 +44,7 @@ public RPCCommunicator(CommunicatorParameters communicatorParameters)
4144
public UnityInput Initialize(UnityOutput unityOutput,
4245
out UnityInput unityInput)
4346
{
47+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
4448
m_isOpen = true;
4549
var channel = new Channel(
4650
"localhost:"+m_communicatorParameters.port,
@@ -57,13 +61,18 @@ public UnityInput Initialize(UnityOutput unityOutput,
5761
#endif
5862
#endif
5963
return result.UnityInput;
64+
#else
65+
throw new UnityAgentsException(
66+
"You cannot perform training on this platform.");
67+
#endif
6068
}
6169

6270
/// <summary>
6371
/// Close the communicator gracefully on both sides of the communication.
6472
/// </summary>
6573
public void Close()
6674
{
75+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
6776
if (!m_isOpen)
6877
{
6978
return;
@@ -78,6 +87,10 @@ public void Close()
7887
{
7988
return;
8089
}
90+
#else
91+
throw new UnityAgentsException(
92+
"You cannot perform training on this platform.");
93+
#endif
8194
}
8295

8396
/// <summary>
@@ -87,6 +100,7 @@ public void Close()
87100
/// <param name="unityOutput">The UnityOutput to be sent.</param>
88101
public UnityInput Exchange(UnityOutput unityOutput)
89102
{
103+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
90104
if (!m_isOpen)
91105
{
92106
return null;
@@ -109,6 +123,10 @@ public UnityInput Exchange(UnityOutput unityOutput)
109123
m_isOpen = false;
110124
return null;
111125
}
126+
#else
127+
throw new UnityAgentsException(
128+
"You cannot perform training on this platform.");
129+
#endif
112130
}
113131

114132
/// <summary>

UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Google.Protobuf;
2-
using Grpc.Core;
32
using System.Net.Sockets;
43
using UnityEngine;
54
using MLAgents.CommunicatorObjects;

protobuf-definitions/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ On Windows & Linux: [See here](https://github.com/google/protobuf/blob/master/sr
2626
1. Install pre-requisites.
2727
2. Un-comment line 4 in `make.bat`, and set to correct Grpc.Tools sub-directory.
2828
3. Run `make.bat`
29+
4. In the generated `UnityToExternalGrpc.cs` file in the `UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects` folder, you will need to add the following to the beginning of the file
30+
31+
```csharp
32+
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
33+
```
34+
and the following line to the end
35+
36+
```csharp
37+
#endif
38+
```
39+
This is to make sure the generated code does not try to access the Grpc library
40+
on platforms that are not supported by Grpc.

0 commit comments

Comments
 (0)