diff --git a/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs b/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
index 7fdfbc7c5..38c556504 100644
--- a/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
+++ b/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
@@ -64,10 +64,12 @@ namespace Unity.MLAgents.Editor
}
EditorGUILayout.PropertyField(so.FindProperty("m_AlternatingRayOrder"), true);
+#if UNITY_2022_3_OR_NEWER
if (is3d)
{
EditorGUILayout.PropertyField(so.FindProperty("m_UseBatchedRaycasts"), true);
}
+#endif
EditorGUILayout.PropertyField(so.FindProperty("rayHitColor"), true);
EditorGUILayout.PropertyField(so.FindProperty("rayMissColor"), true);
diff --git a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
index 55a608666..844d9ec7d 100644
--- a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
+++ b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
@@ -74,10 +74,12 @@ namespace Unity.MLAgents.Sensors
///
public int LayerMask;
+#if UNITY_2022_3_OR_NEWER
///
/// Whether to use batched raycasts.
///
public bool UseBatchedRaycasts;
+#endif
///
/// Returns the expected number of floats in the output.
@@ -252,7 +254,9 @@ namespace Unity.MLAgents.Sensors
RayPerceptionInput m_RayPerceptionInput;
RayPerceptionOutput m_RayPerceptionOutput;
+#if UNITY_2022_3_OR_NEWER
bool m_UseBatchedRaycasts;
+#endif
///
/// Time.frameCount at the last time Update() was called. This is only used for display in gizmos.
@@ -273,8 +277,9 @@ namespace Unity.MLAgents.Sensors
{
m_Name = name;
m_RayPerceptionInput = rayInput;
+#if UNITY_2022_3_OR_NEWER
m_UseBatchedRaycasts = rayInput.UseBatchedRaycasts;
-
+#endif
SetNumObservations(rayInput.OutputSize());
m_DebugLastFrameCount = Time.frameCount;
@@ -348,19 +353,22 @@ namespace Unity.MLAgents.Sensors
{
m_RayPerceptionOutput.RayOutputs = new RayPerceptionOutput.RayOutput[numRays];
}
-
+#if UNITY_2022_3_OR_NEWER
if (m_UseBatchedRaycasts && m_RayPerceptionInput.CastType == RayPerceptionCastType.Cast3D)
{
PerceiveBatchedRays(ref m_RayPerceptionOutput.RayOutputs, m_RayPerceptionInput);
}
else
{
- // For each ray, do the casting and save the results.
- for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
- {
- m_RayPerceptionOutput.RayOutputs[rayIndex] = PerceiveSingleRay(m_RayPerceptionInput, rayIndex);
- }
+#endif
+ // For each ray, do the casting and save the results.
+ for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
+ {
+ m_RayPerceptionOutput.RayOutputs[rayIndex] = PerceiveSingleRay(m_RayPerceptionInput, rayIndex);
}
+#if UNITY_2022_3_OR_NEWER
+ }
+#endif
}
///
@@ -406,22 +414,25 @@ namespace Unity.MLAgents.Sensors
{
RayPerceptionOutput output = new RayPerceptionOutput();
output.RayOutputs = new RayPerceptionOutput.RayOutput[input.Angles.Count];
-
+#if UNITY_2022_3_OR_NEWER
if (batched)
{
PerceiveBatchedRays(ref output.RayOutputs, input);
}
else
{
- for (var rayIndex = 0; rayIndex < input.Angles.Count; rayIndex++)
- {
- output.RayOutputs[rayIndex] = PerceiveSingleRay(input, rayIndex);
- }
+#endif
+ for (var rayIndex = 0; rayIndex < input.Angles.Count; rayIndex++)
+ {
+ output.RayOutputs[rayIndex] = PerceiveSingleRay(input, rayIndex);
}
-
+#if UNITY_2022_3_OR_NEWER
+ }
+#endif
return output;
}
+#if UNITY_2022_3_OR_NEWER
///
/// Evaluate the raycast results of all the rays from the RayPerceptionInput as a batch.
///
@@ -548,6 +559,7 @@ namespace Unity.MLAgents.Sensors
raycastCommands.Dispose();
spherecastCommands.Dispose();
}
+#endif
///
/// Evaluate the raycast results of a single ray from the RayPerceptionInput.
diff --git a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
index 35c4fd532..35255aaad 100644
--- a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
+++ b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
@@ -145,8 +145,9 @@ namespace Unity.MLAgents.Sensors
set { m_AlternatingRayOrder = value; }
}
+#if UNITY_2022_3_OR_NEWER
[HideInInspector, SerializeField]
- [Tooltip("Enable to use batched raycasts and the jobs system.")]
+ [Tooltip("Enable to use batched raycasts and the jobs system. Only available in Unity 2022.3 LTS or newer.")]
public bool m_UseBatchedRaycasts = false;
///
@@ -157,7 +158,7 @@ namespace Unity.MLAgents.Sensors
get { return m_UseBatchedRaycasts; }
set { m_UseBatchedRaycasts = value; }
}
-
+#endif
///
/// Color to code a ray that hits another object.
@@ -303,8 +304,9 @@ namespace Unity.MLAgents.Sensors
rayPerceptionInput.Transform = transform;
rayPerceptionInput.CastType = GetCastType();
rayPerceptionInput.LayerMask = RayLayerMask;
+#if UNITY_2022_3_OR_NEWER
rayPerceptionInput.UseBatchedRaycasts = UseBatchedRaycasts;
-
+#endif
return rayPerceptionInput;
}
@@ -349,6 +351,7 @@ namespace Unity.MLAgents.Sensors
// and there's no way to turn off the "Tag ... is not defined" error logs.
// So just don't use any tags here.
rayInput.DetectableTags = null;
+#if UNITY_2022_3_OR_NEWER
if (m_UseBatchedRaycasts && rayInput.CastType == RayPerceptionCastType.Cast3D)
{
// TODO add call to PerceiveBatchedRays()
@@ -361,12 +364,15 @@ namespace Unity.MLAgents.Sensors
}
else
{
- for (var rayIndex = 0; rayIndex < rayInput.Angles.Count; rayIndex++)
- {
- var rayOutput = RayPerceptionSensor.PerceiveSingleRay(rayInput, rayIndex);
- DrawRaycastGizmos(rayOutput);
- }
+#endif
+ for (var rayIndex = 0; rayIndex < rayInput.Angles.Count; rayIndex++)
+ {
+ var rayOutput = RayPerceptionSensor.PerceiveSingleRay(rayInput, rayIndex);
+ DrawRaycastGizmos(rayOutput);
}
+#if UNITY_2022_3_OR_NEWER
+ }
+#endif
}
}