diff --git a/unity/Runtime/Components/Equality/MjConnect.cs b/unity/Runtime/Components/Equality/MjConnect.cs index 23343089..69e17e06 100644 --- a/unity/Runtime/Components/Equality/MjConnect.cs +++ b/unity/Runtime/Components/Equality/MjConnect.cs @@ -40,6 +40,9 @@ namespace Mujoco { if (Body1 == null || Body2 == null) { throw new NullReferenceException($"Both bodies in connect {name} are required."); } + if (Anchor == null) { + throw new NullReferenceException($"Anchor in connect {name} is required."); + } mjcf.SetAttribute("body1", Body1.MujocoName); mjcf.SetAttribute("body2", Body2.MujocoName); mjcf.SetAttribute("anchor", diff --git a/unity/Runtime/Components/MjGlobalSettings.cs b/unity/Runtime/Components/MjGlobalSettings.cs index e6dccc80..618555e9 100644 --- a/unity/Runtime/Components/MjGlobalSettings.cs +++ b/unity/Runtime/Components/MjGlobalSettings.cs @@ -149,8 +149,7 @@ public struct MjSizeStruct { }; public void ParseMjcf(XmlElement mjcf) { - var localDefault = MjSizeStruct.Default; - Memory = mjcf.GetAttribute("memory", localDefault.Memory); + Memory = mjcf.GetAttribute("memory"); } public XmlElement ToMjcf(XmlElement mjcf) { diff --git a/unity/Runtime/Importer/MjcfImporter.cs b/unity/Runtime/Importer/MjcfImporter.cs index 48c88a92..fe83df5f 100644 --- a/unity/Runtime/Importer/MjcfImporter.cs +++ b/unity/Runtime/Importer/MjcfImporter.cs @@ -134,10 +134,13 @@ public class MjcfImporter { } protected virtual void ParseRoot(GameObject rootObject, XmlElement mujocoNode) { - - var globalsObject = CreateGameObjectInParent("Global Settings", rootObject); - var settingsComponent = globalsObject.AddComponent(); - settingsComponent.ParseGlobalMjcfSections(mujocoNode); + if (mujocoNode.SelectSingleNode("option") != null + || mujocoNode.SelectSingleNode("size") != null + || mujocoNode.SelectSingleNode("custom") != null) { + var globalsObject = CreateGameObjectInParent("Global Settings", rootObject); + var settingsComponent = globalsObject.AddComponent(); + settingsComponent.ParseGlobalMjcfSections(mujocoNode); + } // This makes references to assets. var worldBodyNode = mujocoNode.SelectSingleNode("worldbody") as XmlElement; diff --git a/unity/Tests/Editor/Components/Equality/MjConnectTests.cs b/unity/Tests/Editor/Components/Equality/MjConnectTests.cs index 5308e23f..89225442 100644 --- a/unity/Tests/Editor/Components/Equality/MjConnectTests.cs +++ b/unity/Tests/Editor/Components/Equality/MjConnectTests.cs @@ -24,6 +24,7 @@ namespace Mujoco { public class MjConnectTests { private MjBody _body1; private MjBody _body2; + private Transform _anchor; private MjConnect _constraint; private XmlDocument _doc; @@ -31,6 +32,7 @@ namespace Mujoco { public void SetUp() { _body1 = new GameObject("body1").AddComponent(); _body2 = new GameObject("body2").AddComponent(); + _anchor = _body1.transform; _constraint = new GameObject("connect").AddComponent(); _doc = new XmlDocument(); } @@ -44,10 +46,7 @@ namespace Mujoco { [Test] public void ErrorThrownWhenBody1Empty() { - // This is an illegal MJCF, but the purpose of this test is to verify that if - // the user didn't assign the body in the editor, an error will be thrown when play is hit. - _doc.LoadXml(""); - _constraint.ParseMjcf(_doc.GetElementsByTagName("body")[0] as XmlElement); + _constraint.Body1 = null; Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception); } @@ -71,10 +70,12 @@ namespace Mujoco { public void GenerateXML() { _constraint.Body1 = _body1; _constraint.Body2 = _body2; + _constraint.Anchor = _anchor; var mjcf = _constraint.GenerateMjcf("name", _doc); Assert.That(mjcf.OuterXml, Does.Contain("