Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Corrected behaviour of TrackedPoseDriver when no device is connected. #1823

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
29 changes: 29 additions & 0 deletions Assets/Tests/InputSystem/Plugins/XRTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrackedPoseDriver>();
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()
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed arrow key navigation of Input Actions after Action rename. [ISXB-1024](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1024)
- Fixed gamepad navigation in UI Toolkit TextField when using InputSystemUIInputModule. [UUM-77364](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-77364)
- Fixed issue where asset editor window splitter positions were not persisted [ISXB-1316]
- Fixed a bug that would case `TrackedPoseDriver` 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.

### Changed
- Changed default input action asset name from New Controls to New Actions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down