Skip to content

update defines, compile out Initialize body on non-desktop #4957

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
merged 2 commits into from
Feb 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#define MLA_SUPPORTED_TRAINING_PLATFORM
#endif

# if MLA_SUPPORTED_TRAINING_PLATFORM
using Grpc.Core;
#endif
#if UNITY_EDITOR
Expand Down Expand Up @@ -44,7 +48,7 @@ internal class RpcCommunicator : ICommunicator
Dictionary<string, ActionSpec> m_UnsentBrainKeys = new Dictionary<string, ActionSpec>();


#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
/// The Unity to External client.
UnityToExternalProto.UnityToExternalProtoClient m_Client;
#endif
Expand Down Expand Up @@ -97,6 +101,7 @@ string pythonApiVersion
/// <param name="initParametersOut">The External Initialization Parameters received.</param>
public bool Initialize(CommunicatorInitParameters initParameters, out UnityRLInitParameters initParametersOut)
{
#if MLA_SUPPORTED_TRAINING_PLATFORM
var academyParameters = new UnityRLInitializationOutputProto
{
Name = initParameters.name,
Expand Down Expand Up @@ -183,6 +188,10 @@ out input
UpdateEnvironmentWithInput(input.RlInput);
initParametersOut = initializationInput.RlInitializationInput.ToUnityRLInitParameters();
return true;
#else
initParametersOut = new UnityRLInitParameters();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still reference the grpc stuff?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is the C#-only class.

The breaking change in the other PR was referencing RpcException and the status codes, the classes in the signature didn't change (although the return value was moved to an out parameter)

return false;
#endif
}

/// <summary>
Expand Down Expand Up @@ -213,7 +222,7 @@ void UpdateEnvironmentWithInput(UnityRLInputProto rlInput)

UnityInputProto Initialize(UnityOutputProto unityOutput, out UnityInputProto unityInput)
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
m_IsOpen = true;
var channel = new Channel(
"localhost:" + m_CommunicatorInitParameters.port,
Expand Down Expand Up @@ -246,7 +255,7 @@ UnityInputProto Initialize(UnityOutputProto unityOutput, out UnityInputProto uni
/// </summary>
public void Dispose()
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
if (!m_IsOpen)
{
return;
Expand Down Expand Up @@ -447,7 +456,7 @@ public ActionBuffers GetActions(string behaviorName, int agentId)
/// <param name="unityOutput">The UnityOutput to be sent.</param>
UnityInputProto Exchange(UnityOutputProto unityOutput)
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
if (!m_IsOpen)
{
return null;
Expand Down