Skip to content

FIX: [XRA-675] PoseControl isTracked returns false via non-optimized read paths#2443

Open
kevin-zakszewski wants to merge 8 commits into
developfrom
bugfix/XRA-675-PoseControl-isTracked-false-bug
Open

FIX: [XRA-675] PoseControl isTracked returns false via non-optimized read paths#2443
kevin-zakszewski wants to merge 8 commits into
developfrom
bugfix/XRA-675-PoseControl-isTracked-false-bug

Conversation

@kevin-zakszewski

@kevin-zakszewski kevin-zakszewski commented Jul 2, 2026

Copy link
Copy Markdown

Description

XRA-675

Fix PoseControl.isTracked always returning false via non-optimized read paths

PoseState.isTracked was declared with sizeInBits = 8 to enable the kFormatPose optimization. However, this caused InputStateBlock.ReadFloat() to treat the bool byte value as an 8-bit normalized quantity (1/255 ≈ 0.004) instead of a discrete 0.0 or 1.0. Since 0.004 falls below the 0.5 button press threshold, isTracked always returned false when read through non-optimized code paths, including the Input Debugger.

Summary of Changes

PoseControl.cs — two changes:

  1. PoseState.isTracked: Changed sizeInBits = 8 to sizeInBits = 1. This makes InputStateBlock.ReadFloat() use the ReadSingleBit path, which correctly returns 0.0f or 1.0f. The struct layout is unaffected - StructLayout(LayoutKind.Explicit) with FieldOffset attributes controls the memory layout independently of sizeInBits.
  2. PoseControl.CalculateOptimizedControlDataType(): Updated the isTracked validation from isTracked.optimizedControlDataType == InputStateBlock.kFormatByte to checking isTracked.optimizedControlDataType == InputStateBlock.kFormatBit. This preserves the kFormatPose fast path (direct *(PoseState*)ptr struct cast), which remains valid because the C# bool at byte 0 is always stored as a full byte (0 or 1) regardless of the declared bit width.

Testing status & QA

Added the test Controls_PoseControl_IsTracked_ReadsCorrectly - parameterized with [TestCase(true)] and [TestCase(false)] to run with optimized controls both enabled and disabled. For each case it:

  • Queues a state event with isTracked = 1 and verifies:
    • poseControl.isTracked.isPressed returns true
    • poseControl.isTracked.ReadValue() returns 1.0f
    • poseControl.ReadValue().isTracked returns true
  • Queues a state event with isTracked = 0 and verifies all three return false/0.0f

Overall Product Risks

  • Complexity: 0
  • Halo Effect: 0

Comments to reviewers

With this fix, isTracked gains a ButtonControl-level optimization — it previously got kFormatByte (via sizeInBits = 8), and now allows a fast path for 1-bit controls. The PoseControl was updated for this new optimized control data type for isTracked to allow it to use the kFormatPose optimization.

I looked into adding a kFormatBit optimization to AxisControl so that 1-bit ButtonControls would inherit a direct ReadSingleBit fast path. This would restore the optimization for isTracked, put the PoseControl check back on the standard optimizedControlDataType pipeline, and benefit other 1-bit buttons or axes in the system (mouse, keyboard, gamepad, etc.). The main concern is the wider blast radius — it touches AxisControl, which affects every device type, so it would need a proper audit and test pass.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

@cla-assistant-unity

cla-assistant-unity Bot commented Jul 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kevin-zakszewski kevin-zakszewski changed the title Bugfix/xra 675 pose control is tracked false bug FIX: [XRA-675] PoseControl isTracked returns false via non-optimized read paths Jul 2, 2026
@kevin-zakszewski kevin-zakszewski marked this pull request as ready for review July 2, 2026 23:37

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

LGTM

The fix is focused, but the new Pose fast-path gate now accepts isTracked configurations that the old check deliberately excluded, which can make the parent control bypass child-control semantics in overridden layouts.

Reviewed commit 1fdc5db4

🤖 Helpful? 👍/👎

@codecov-github-com

codecov-github-com Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff              @@
##           develop    #2443       +/-   ##
============================================
+ Coverage    58.58%   79.02%   +20.44%     
============================================
  Files          738      766       +28     
  Lines       135831   140451     +4620     
============================================
+ Hits         79570   110995    +31425     
+ Misses       56261    29456    -26805     
Flag Coverage Δ
inputsystem_MacOS_6000.0 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.0_project 77.49% <100.00%> (+0.24%) ⬆️
inputsystem_MacOS_6000.3 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.3_project 77.49% <100.00%> (+0.27%) ⬆️
inputsystem_MacOS_6000.4 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.4_project 77.50% <100.00%> (+0.27%) ⬆️
inputsystem_MacOS_6000.5 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.5_project 77.53% <100.00%> (+0.27%) ⬆️
inputsystem_MacOS_6000.6 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.6_project 77.53% <100.00%> (+0.27%) ⬆️
inputsystem_Ubuntu_6000.0 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.0_project 77.40% <100.00%> (+0.24%) ⬆️
inputsystem_Ubuntu_6000.3 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.3_project 77.39% <100.00%> (+0.27%) ⬆️
inputsystem_Ubuntu_6000.4 5.32% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.4_project 77.41% <100.00%> (+0.27%) ⬆️
inputsystem_Ubuntu_6000.5 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.5_project 77.44% <100.00%> (+0.27%) ⬆️
inputsystem_Ubuntu_6000.6 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.6_project 77.44% <100.00%> (+0.27%) ⬆️
inputsystem_Windows_6000.0 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.0_project 77.61% <100.00%> (+0.24%) ⬆️
inputsystem_Windows_6000.3 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.3_project 77.61% <100.00%> (+0.26%) ⬆️
inputsystem_Windows_6000.4 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.4_project 77.62% <100.00%> (+0.26%) ⬆️
inputsystem_Windows_6000.5 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.5_project 77.66% <100.00%> (+0.26%) ⬆️
inputsystem_Windows_6000.6 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.6_project 77.66% <100.00%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/CoreTests_Controls.cs 99.80% <100.00%> (+<0.01%) ⬆️
Assets/Tests/InputSystem/Plugins/XRTests.cs 96.36% <100.00%> (+0.28%) ⬆️
...system/InputSystem/Runtime/Controls/AxisControl.cs 93.97% <ø> (+71.08%) ⬆️
...stem/InputSystem/Runtime/Controls/ButtonControl.cs 88.88% <100.00%> (+64.18%) ⬆️
...tSystem/Runtime/Plugins/XR/Controls/PoseControl.cs 58.82% <ø> (ø)

... and 275 files with indirect coverage changes

ℹ️ Need help interpreting these results?

@MorganHoarau MorganHoarau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimization guard update is correct, and the test covers the regression in both execution path. Would be nice to add proper optimization path for 1-bit in ButtonControl, but I can do that on a different PR if preferred.

FYI @chris-massie

Also updates the mouse test that I believe would be impacted by the change.

@chris-massie chris-massie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with a scene that displayed the Is Tracked status of controller poses from the Hand Interaction Profile. Obscuring the controller under the desk and waiting eventually caused the device to report false for Is Tracked, and returning above the desk in view of the HMD made the device report true. I also verified the Debugger Window shows 1 instead of 0.003921569, and reading Assert.AreEqual(device.devicePose.isTracked.value, device.isTracked.value) now properly passes with the OculusTouchControllerProfile.OculusTouchController after this fix.

@MorganHoarau MorganHoarau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes and updating the relevant test!

PR description's Comments to reviewers needs to be updated.

@chris-massie

Copy link
Copy Markdown
Collaborator

PR description's Comments to reviewers needs to be updated.

I updated the description to reflect your suggestion being applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants