From 139328f86e7e9d74404dd5afd8f9cd626d267f5e Mon Sep 17 00:00:00 2001 From: Tom Erez Date: Wed, 26 Apr 2023 23:29:19 -0700 Subject: [PATCH] Clarify error messages when Unity fails to step the scene. PiperOrigin-RevId: 527486144 Change-Id: I4e889977e035e13557c114e875ea0ba32da79002 --- unity/Runtime/Components/MjScene.cs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/unity/Runtime/Components/MjScene.cs b/unity/Runtime/Components/MjScene.cs index 9e8eed7f..6d80893e 100644 --- a/unity/Runtime/Components/MjScene.cs +++ b/unity/Runtime/Components/MjScene.cs @@ -62,7 +62,7 @@ public class MjScene : MonoBehaviour { return _instance; } } - + public static bool InstanceExists { get => _instance != null; } public void Awake() { @@ -178,12 +178,12 @@ public class MjScene : MonoBehaviour { XmlDocument mjcf, IEnumerable components) { Model = MjEngineTool.LoadModelFromString(mjcf.OuterXml); if (Model == null) { - throw new NullReferenceException("Failed to create Mujoco runtime model."); + throw new NullReferenceException("Model loading failed, see other errors for root cause."); } else { Data = MujocoLib.mj_makeData(Model); } if (Data == null) { - throw new NullReferenceException("Failed to create Mujoco runtime data."); + throw new NullReferenceException("Model loaded but mj_makeData failed."); } // Bind the components to their Mujoco counterparts. @@ -472,18 +472,15 @@ public class MjScene : MonoBehaviour { Debug.LogWarning("Failed to save Xml to a file: " + ex.ToString(), this); } } - - } - public class MjStepArgs : EventArgs - { - public unsafe MjStepArgs(MujocoLib.mjModel_* model, MujocoLib.mjData_* data){ - this.model = model; - this.data = data; - } - public readonly unsafe MujocoLib.mjModel_* model; - public readonly unsafe MujocoLib.mjData_* data; +public class MjStepArgs : EventArgs +{ + public unsafe MjStepArgs(MujocoLib.mjModel_* model, MujocoLib.mjData_* data){ + this.model = model; + this.data = data; } - -} \ No newline at end of file + public readonly unsafe MujocoLib.mjModel_* model; + public readonly unsafe MujocoLib.mjData_* data; +} +}