From 0a4495f6e26b80368dea284ad98f5e48568495fc Mon Sep 17 00:00:00 2001 From: Jason Rupert Date: Wed, 21 Dec 2022 12:56:02 -0800 Subject: [PATCH] Fix to prevent SetModel from being called before it is ready to be used. --- .../SharedAssets/Scripts/ModelCarousel.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelCarousel.cs b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelCarousel.cs index 891fc4bb0..60cb9acd1 100644 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelCarousel.cs +++ b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelCarousel.cs @@ -47,8 +47,6 @@ public class ModelCarousel : MonoBehaviour private NNModel m_OriginalModel = null; - private int k_FixedUpdatePerSecond; - // The attached Agent Agent m_Agent; @@ -61,12 +59,17 @@ public class ModelCarousel : MonoBehaviour } #endif - private void Reset() + private void Reset(bool setModel) { m_Reset = false; m_StepsSinceLastSwitch = 0; m_CurrentModelIndex = 0; - m_Agent.SetModel(m_OriginalModel.name, m_OriginalModel); + + if (setModel) + { + m_Agent.SetModel(m_OriginalModel.name, m_OriginalModel); + } + textMeshComponent?.SetText("Ready to Start"); } @@ -75,9 +78,7 @@ public class ModelCarousel : MonoBehaviour m_Agent = GetComponent(); m_OriginalModel = m_Agent.GetComponent().Model; - Reset(); - - k_FixedUpdatePerSecond = (int)(1.0f / Time.fixedDeltaTime); + Reset(false); if (m_TimeScaleOverride > 0.0f) { @@ -160,7 +161,7 @@ public class ModelCarousel : MonoBehaviour if (m_Reset) { StopRecording(); - Reset(); + Reset(true); m_Pause = true; m_Start = false; } @@ -175,7 +176,7 @@ public class ModelCarousel : MonoBehaviour m_StepsSinceLastSwitch++; - if (m_StepsSinceLastSwitch >= m_SecondsBetweenSwitches * k_FixedUpdatePerSecond || m_ForceNext) + if (m_StepsSinceLastSwitch >= (m_SecondsBetweenSwitches / Time.fixedDeltaTime) || m_ForceNext) { m_ForceNext = false; m_StepsSinceLastSwitch = 0;