From 2388b651e8a978dacb3eb723ed3bcb25fc177899 Mon Sep 17 00:00:00 2001 From: Tom Erez Date: Mon, 15 Jan 2024 12:03:32 -0800 Subject: [PATCH] Unity plug-in: Fix for when xml file has no section. PiperOrigin-RevId: 598646137 Change-Id: Id27635dc3064f8568ae0d86c2cdee8c2d414dd2f --- unity/Runtime/Components/Joints/MjJointSettings.cs | 2 +- unity/Runtime/Components/MjActuator.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unity/Runtime/Components/Joints/MjJointSettings.cs b/unity/Runtime/Components/Joints/MjJointSettings.cs index 1bd684c6..322d6568 100644 --- a/unity/Runtime/Components/Joints/MjJointSettings.cs +++ b/unity/Runtime/Components/Joints/MjJointSettings.cs @@ -166,7 +166,7 @@ namespace Mujoco { FrictionLoss = mjcf.GetFloatAttribute("frictionloss", 0.0f); bool defaultLimited = false; - if ((mjcf.OwnerDocument.GetElementsByTagName("compiler") [0]["compiler"]) + if ((mjcf.OwnerDocument.GetElementsByTagName("compiler")[0]?["compiler"]) ?.GetBoolAttribute("autolimits", true) ?? true) { defaultLimited = mjcf.HasAttribute("range"); diff --git a/unity/Runtime/Components/MjActuator.cs b/unity/Runtime/Components/MjActuator.cs index bf937e45..9aacf2bf 100644 --- a/unity/Runtime/Components/MjActuator.cs +++ b/unity/Runtime/Components/MjActuator.cs @@ -82,9 +82,9 @@ public class MjActuator : MjComponent { 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"]) + bool autolimits = (mjcf.OwnerDocument.GetElementsByTagName("compiler")[0]?["compiler"]) ?.GetBoolAttribute("autolimits", true) ?? - true; + false; CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", defaultValue: autolimits ? CtrlRange != Vector2.zero : false); ForceLimited = mjcf.GetBoolAttribute("forcelimited",