diff --git a/unity/Runtime/Components/Joints/MjJointSettings.cs b/unity/Runtime/Components/Joints/MjJointSettings.cs index f2f3d72e7e..1bd684c672 100644 --- a/unity/Runtime/Components/Joints/MjJointSettings.cs +++ b/unity/Runtime/Components/Joints/MjJointSettings.cs @@ -164,7 +164,15 @@ public void FromMjcf(XmlElement mjcf) { RefFriction.FromMjcf(mjcf, "solreffriction"); ImpFriction.FromMjcf(mjcf, "solimpfriction"); FrictionLoss = mjcf.GetFloatAttribute("frictionloss", 0.0f); - Limited = mjcf.GetBoolAttribute("limited", false); + + bool defaultLimited = false; + if ((mjcf.OwnerDocument.GetElementsByTagName("compiler") [0]["compiler"]) + ?.GetBoolAttribute("autolimits", true) ?? + true) { + defaultLimited = mjcf.HasAttribute("range"); + } + + Limited = mjcf.GetBoolAttribute("limited", defaultLimited); Margin = mjcf.GetFloatAttribute("margin", defaultValue: 0.0f); } } diff --git a/unity/Runtime/Components/MjActuator.cs b/unity/Runtime/Components/MjActuator.cs index 4bdffe87c4..bf937e459e 100644 --- a/unity/Runtime/Components/MjActuator.cs +++ b/unity/Runtime/Components/MjActuator.cs @@ -77,12 +77,18 @@ public void ToMjcf(XmlElement mjcf) { } public void FromMjcf(XmlElement mjcf) { - CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", defaultValue: false); - ForceLimited = mjcf.GetBoolAttribute("forcelimited", defaultValue: false); CtrlRange = mjcf.GetVector2Attribute("ctrlrange", defaultValue: Vector2.zero); ForceRange = mjcf.GetVector2Attribute("forcerange", defaultValue: Vector2.zero); LengthRange = mjcf.GetVector2Attribute("lengthrange", defaultValue: Vector2.zero); Gear = mjcf.GetFloatArrayAttribute("gear", defaultValue: new float[] { 1.0f }).ToList(); + + bool autolimits = (mjcf.OwnerDocument.GetElementsByTagName("compiler")[0]["compiler"]) + ?.GetBoolAttribute("autolimits", true) ?? + true; + CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", + defaultValue: autolimits ? CtrlRange != Vector2.zero : false); + ForceLimited = mjcf.GetBoolAttribute("forcelimited", + defaultValue: autolimits ? ForceRange != Vector2.zero : false); } }