Skip to content

Commit d9b493a

Browse files
author
Henry Peteet
authored
Fix analytics error when compiling XBOX and PS5 (#5628)
* Add ENABLE_CLOUD_SERVICES_ANALYTICS Guards To use analytics safely you must wrap usage with `#if ENABLE_CLOUD_SERVICES_ANALYTICS` See https://docs.unity3d.com/ScriptReference/Analytics.Analytics.html
1 parent 5a25d78 commit d9b493a

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

com.unity.ml-agents/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to
3838

3939
### Bug Fixes
4040
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
41+
- Fixed a bug where ml-agents code wouldn't compile on platforms that didn't support analytics (PS4/5, XBoxOne) (#5628)
4142

4243
#### ml-agents / ml-agents-envs / gym-unity (Python)
4344
- Fixed a bug where the critics were not being normalized during training. (#5595)

com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Unity.MLAgents.Sensors;
88
using UnityEngine;
99

10-
#if MLA_UNITY_ANALYTICS_MODULE
10+
#if MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
1111
using UnityEngine.Analytics;
1212
#endif
1313

@@ -44,7 +44,7 @@ internal class InferenceAnalytics
4444
const int k_MaxNumberOfElements = 1000;
4545

4646

47-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
47+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
4848
/// <summary>
4949
/// Models that we've already sent events for.
5050
/// </summary>
@@ -53,7 +53,7 @@ internal class InferenceAnalytics
5353

5454
static bool EnableAnalytics()
5555
{
56-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
56+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
5757
if (s_EventRegistered)
5858
{
5959
return true;
@@ -106,7 +106,7 @@ public static void InferenceModelSet(
106106
IList<IActuator> actuators
107107
)
108108
{
109-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
109+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
110110
// The event shouldn't be able to report if this is disabled but if we know we're not going to report
111111
// Lets early out and not waste time gathering all the data
112112
if (!IsAnalyticsEnabled())

com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
using Unity.MLAgents.Sensors;
66
using UnityEngine;
77
#if MLA_UNITY_ANALYTICS_MODULE
8+
9+
#if ENABLE_CLOUD_SERVICES_ANALYTICS
810
using UnityEngine.Analytics;
11+
#endif
12+
913
#if UNITY_EDITOR
1014
using UnityEditor.Analytics;
1115
#endif
@@ -43,7 +47,7 @@ internal static class TrainingAnalytics
4347

4448
private static bool s_SentEnvironmentInitialized;
4549

46-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
50+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
4751
/// <summary>
4852
/// Whether or not we've registered this particular event yet
4953
/// </summary>
@@ -64,7 +68,7 @@ internal static class TrainingAnalytics
6468

6569
internal static bool EnableAnalytics()
6670
{
67-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
71+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
6872
if (s_EventsRegistered)
6973
{
7074
return true;
@@ -106,7 +110,7 @@ public static void SetTrainerInformation(string packageVersion, string communica
106110

107111
public static bool IsAnalyticsEnabled()
108112
{
109-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
113+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
110114
return EditorAnalytics.enabled;
111115
#else
112116
return false;
@@ -135,7 +139,7 @@ public static void TrainingEnvironmentInitialized(TrainingEnvironmentInitialized
135139
// Debug.Log(
136140
// $"Would send event {k_TrainingEnvironmentInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
137141
// );
138-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
142+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
139143
if (AnalyticsUtils.s_SendEditorAnalytics)
140144
{
141145
EditorAnalytics.SendEventWithLimit(k_TrainingEnvironmentInitializedEventName, tbiEvent);
@@ -151,7 +155,7 @@ public static void RemotePolicyInitialized(
151155
IList<IActuator> actuators
152156
)
153157
{
154-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
158+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
155159
if (!IsAnalyticsEnabled())
156160
return;
157161

@@ -208,7 +212,7 @@ internal static TrainingBehaviorInitializedEvent SanitizeTrainingBehaviorInitial
208212
[Conditional("MLA_UNITY_ANALYTICS_MODULE")]
209213
public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent rawTbiEvent)
210214
{
211-
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
215+
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
212216
if (!IsAnalyticsEnabled())
213217
return;
214218

0 commit comments

Comments
 (0)