diff --git a/Assets/Tests/InputSystem/Plugins/XRTests.cs b/Assets/Tests/InputSystem/Plugins/XRTests.cs index 65bc96c166..e90a742635 100644 --- a/Assets/Tests/InputSystem/Plugins/XRTests.cs +++ b/Assets/Tests/InputSystem/Plugins/XRTests.cs @@ -728,6 +728,35 @@ public void Components_TrackedPoseDriver_RetainsPoseWhenTrackedDeviceRemoved() } } + [Test] + [Category("Components")] + public void Components_TrackedPoseDriver_RetainsPoseWhenNoTrackedDeviceIsConnected() + { + // Tests/reproduces the scenario described in https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-699 + // i.e. that rotation and/or position is not updated if device is not connected and track state isn't ignored. + + var position = new Vector3(1f, 2f, 3f); + var rotation = new Quaternion(0.09853293f, 0.09853293f, 0.09853293f, 0.9853293f); + + var go = new GameObject(); + go.transform.position = position; + go.transform.rotation = rotation; + + var tpd = go.AddComponent(); + tpd.updateType = TrackedPoseDriver.UpdateType.Update; + tpd.trackingType = TrackedPoseDriver.TrackingType.RotationAndPosition; + tpd.ignoreTrackingState = false; + var transform = tpd.transform; + + Assert.That(transform.position, Is.EqualTo(position)); + Assert.That(transform.rotation, Is.EqualTo(rotation)); + + InputSystem.Update(InputUpdateType.Dynamic); + + Assert.That(transform.position, Is.EqualTo(position)); + Assert.That(transform.rotation, Is.EqualTo(rotation)); + } + [Test] [Category("Layouts")] public void Layouts_PoseControlsCanBeCreatedBySubcontrols() diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index caf4b4ec58..4d1afd63ec 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845) - Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141) - Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on 2022.3. [ISXB-1151](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1151) +- Fixed a bug that would case `TrackedBasedDriver` to update position and rotation when no HMD device is connected [ISXB-699](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-699) instead of keeping it unchanged. - Fixed unexpected control scheme switch when using `OnScreenControl` and pointer based schemes which registed "Cancel" event on every frame.[ISXB-656](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-656) - Fixed an issue with The "Add Control Scheme..." popup window so that it now persists until any changes are explicitly Saved or Cancelled [case ISXB-1131](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1131) @@ -245,6 +246,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed incorrect documentation in InputSystem.actions and InputSystem.onActionsChanged property API contract. - Fixed an issue where `InputSystem.actions` could be incorrectly evaluated if the associated asset was deleted. + ## [1.8.0-pre.2] - 2023-11-09 ### Changed diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/TrackedPoseDriver.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/TrackedPoseDriver.cs index 59b92283b5..428b2121fa 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/TrackedPoseDriver.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/TrackedPoseDriver.cs @@ -500,7 +500,27 @@ void ReadTrackingState() { // Treat an Input Action Reference with no reference the same as // an enabled Input Action with no authored bindings, and allow driving the Transform pose. - m_CurrentTrackingState = TrackingStates.Position | TrackingStates.Rotation; + // TODO Remove if suggested fix seems valid. m_CurrentTrackingState = TrackingStates.Position | TrackingStates.Rotation; + + // Check if we have transform and rotation controls to drive the pose. + var positionInputAction = m_PositionInput.action; + var rotationInputAction = m_RotationInput.action; + if (positionInputAction != null && positionInputAction.m_BindingsCount > 0 && rotationInputAction != null && rotationInputAction.m_BindingsCount > 0) + { + m_CurrentTrackingState = TrackingStates.Position | TrackingStates.Rotation; + } + else if (positionInputAction != null && positionInputAction.m_BindingsCount > 0) + { + m_CurrentTrackingState = TrackingStates.Position; + } + else if (rotationInputAction != null && rotationInputAction.m_BindingsCount > 0) + { + m_CurrentTrackingState = TrackingStates.Rotation; + } + else + { + m_CurrentTrackingState = TrackingStates.None; + } return; }