Skip to content

ISX-2228: Add OrientationSensor (device orientation parity) - #2468

Open
K-Tone wants to merge 8 commits into
im-parity/stagingfrom
anthony/im-parity-orientation
Open

ISX-2228: Add OrientationSensor (device orientation parity)#2468
K-Tone wants to merge 8 commits into
im-parity/stagingfrom
anthony/im-parity-orientation

Conversation

@K-Tone

@K-Tone K-Tone commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a DeviceOrientationSensor to the Input System package, giving feature parity with the legacy UnityEngine.Input.deviceOrientation (ISX-2228, part of the IM API parity epic ISX-2108).

The Input System had every raw motion sensor but no discrete physical-orientation value. This adds one, modeled on the existing sensor + enum-control patterns.

What's in this PR (managed / package side)

  • DeviceOrientation enum (UnityEngine.InputSystem) — package-local, values identical to the legacy UnityEngine.DeviceOrientation (Unknown=0 … FaceDown=6). Kept independent of the legacy input module so the package stays self-contained.
  • DeviceOrientationControl : InputControl<DeviceOrientation> — enum-backed control, modeled on TouchPhaseControl.
  • DeviceOrientationSensor : Sensor + DeviceOrientationState (FourCC 'ORNT', int orientation). Reports the raw physical orientation — deliberately not run through screen-orientation compensation.
  • Registered the "DeviceOrientation" control and "DeviceOrientationSensor" device layouts.
  • Platform layout matchers: iOS and Android map their native orientation device (deviceClass "DeviceOrientation") to DeviceOrientationSensor. WebGL/UWP match by the full layout name directly (no matcher needed).
  • Unity Remote: handle the existing DeviceOrientation message (type 4) — no Remote-app change required — and surface a DeviceOrientationSensor while connected.

Tests

  • Devices_CanGetDeviceOrientationReading (mock runtime) + DeviceOrientationSensor added to Devices_CanCreateDevice.
  • Remote_CanReceiveDeviceOrientationFromUnityRemote.

Companion PR

Native per-platform producers that feed this device live in unity.git (trunk): ISX-2228 native device orientation producers. Both are needed end-to-end (and land together — device matching depends on both the matcher and the native descriptor.type agreeing); this managed side also gets mirrored into unity.git/ShadowPackages at publish time.

Notes

  • Usage: DeviceOrientationSensor.current.orientation.ReadValue() (enable the device first, like any sensor).
  • Consumers with both using UnityEngine; and using UnityEngine.InputSystem; disambiguate DeviceOrientation with a using alias — the same established pattern as Gyroscope/TouchPhase.

🤖 Generated with Claude Code

K-Tone and others added 4 commits August 7, 2026 14:34
Add an OrientationSensor device to the Input System package that reports
the physical device orientation as a discrete value, providing feature
parity with the legacy UnityEngine.Input.deviceOrientation property.

- Add package-local UnityEngine.InputSystem.DeviceOrientation enum
  (values identical to the legacy enum, kept independent of the legacy
  input module).
- Add OrientationControl : InputControl<DeviceOrientation>, modeled on
  TouchPhaseControl.
- Add OrientationState (FourCC 'ORNT') and OrientationSensor : Sensor.
  The reported value is deliberately not compensated for screen
  orientation.
- Register the "Orientation" control and "OrientationSensor" device
  layouts.
- Add a mock-runtime unit test and cover OrientationSensor in
  Devices_CanCreateDevice.

Native producers (per-platform) and docs/changelog follow in later
changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a layout matcher so the native iOS orientation device (interface
"iOS", deviceClass "Orientation") resolves to the OrientationSensor
layout, following the same convention as the Gravity/Attitude/
LinearAcceleration sensors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a layout matcher so the native Android orientation device (interface
"Android", deviceClass "Orientation") resolves to the OrientationSensor
layout. Unlike the other Android sensors it is not an ASensor, so it maps
directly to the base layout rather than an AndroidSensor variant.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Surface an OrientationSensor when connected to the Unity Remote so device
orientation can be tested in the Editor.

- Handle the existing MessageType.DeviceOrientation message (the Remote app
  already sends it) and queue it to an OrientationSensor added on connect.
  No change to the Remote app is required.
- Add a DeviceOrientationMessage struct matching HandleOrientationMessage in
  GenericRemote.cpp (header + int32 orientation, same enum values as ours).
- Remove the device on disconnect and clear it on manual removal.
- Add Remote_CanReceiveDeviceOrientationFromUnityRemote test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@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 runtime integration follows the existing sensor and Unity Remote patterns, but the PR leaves the documented migration path inaccurate and adds an unrelated project-wide dependency.

P2

The shipped documentation still says Input.deviceOrientation has “No corresponding API yet” in Documentation~/corresponding-old-new-api.md, and Documentation~/supported-sensors-reference.md omits the new sensor. Users following the migration guide or support matrix will therefore conclude this feature is unavailable. Update those references to point to OrientationSensor.current.orientation.ReadValue() and document its supported platforms.

Reviewed commit 732016b

🤖 Helpful? 👍/👎

Comment thread Packages/manifest.json
@K-Tone
K-Tone changed the base branch from develop to im-parity/staging August 7, 2026 14:08
@codecov-github-com

codecov-github-com Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 88.05970% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...InputSystem/Runtime/Controls/OrientationControl.cs 66.66% 4 Missing ⚠️
...sets/Tests/InputSystem/Plugins/UnityRemoteTests.cs 80.00% 3 Missing ⚠️
...m/Editor/Plugins/UnityRemote/UnityRemoteSupport.cs 91.66% 1 Missing ⚠️
@@                 Coverage Diff                  @@
##             im-parity/staging    #2468   +/-   ##
====================================================
  Coverage                     ?   78.96%           
====================================================
  Files                        ?      768           
  Lines                        ?   140874           
  Branches                     ?        0           
====================================================
  Hits                         ?   111242           
  Misses                       ?    29632           
  Partials                     ?        0           
Flag Coverage Δ
inputsystem_MacOS_6000.0_project 77.50% <88.05%> (?)
inputsystem_MacOS_6000.3_project 77.50% <88.05%> (?)
inputsystem_MacOS_6000.5_project 77.55% <88.05%> (?)
inputsystem_MacOS_6000.6_project 77.55% <88.05%> (?)
inputsystem_MacOS_6000.7_project 77.55% <88.05%> (?)
inputsystem_Ubuntu_6000.0_project 77.41% <88.05%> (?)
inputsystem_Ubuntu_6000.3_project 77.40% <88.05%> (?)
inputsystem_Ubuntu_6000.5_project 77.46% <88.05%> (?)
inputsystem_Ubuntu_6000.6_project 77.47% <88.05%> (?)
inputsystem_Ubuntu_6000.7_project 77.46% <88.05%> (?)
inputsystem_Windows_6000.0_project 77.57% <88.05%> (?)
inputsystem_Windows_6000.3_project 77.56% <88.05%> (?)
inputsystem_Windows_6000.5_project 77.63% <88.05%> (?)
inputsystem_Windows_6000.6_project 77.63% <88.05%> (?)
inputsystem_Windows_6000.7_project 77.63% <88.05%> (?)

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

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/CoreTests_Devices.cs 98.24% <100.00%> (ø)
....inputsystem/InputSystem/Runtime/Devices/Sensor.cs 99.56% <100.00%> (ø)
...ty.inputsystem/InputSystem/Runtime/InputManager.cs 89.02% <100.00%> (ø)
...utSystem/Runtime/Plugins/Android/AndroidSupport.cs 94.00% <100.00%> (ø)
...stem/InputSystem/Runtime/Plugins/iOS/iOSSupport.cs 76.47% <100.00%> (ø)
...m/Editor/Plugins/UnityRemote/UnityRemoteSupport.cs 91.92% <91.66%> (ø)
...sets/Tests/InputSystem/Plugins/UnityRemoteTests.cs 95.48% <80.00%> (ø)
...InputSystem/Runtime/Controls/OrientationControl.cs 66.66% <66.66%> (ø)

ℹ️ Need help interpreting these results?

Comment thread Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Sensor.cs Outdated
K-Tone and others added 2 commits August 10, 2026 12:36
Review feedback: the name OrientationSensor reads ambiguously against
screen orientation. Rename the public device (and its layout name) to
DeviceOrientationSensor. Matchers, Unity Remote, and tests updated to
match. The DeviceOrientation enum and OrientationControl are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Review feedback (morgan): keep the state struct name consistent with the
DeviceOrientationSensor device. Stays in sync with the native struct via the
'ORNT' FourCC. Test + Unity Remote references updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@K-Tone

K-Tone commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

@u-pr Can you check if all the reviewer comments have been fixed thus far?

@u-pr

u-pr Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Yes, all reviewer comments have been addressed:

  1. Unintended manifest dependency (Packages/manifest.json)u-pr[bot]

    • Status: Fixed.
    • Packages/manifest.json has been reverted and is no longer part of the PR diff.
  2. Rename sensor to DeviceOrientationSensor (Sensor.cs)MorganHoarau

    • Status: Fixed.
    • The sensor has been renamed to DeviceOrientationSensor across the codebase, including:
      • The class definition and doc comments in Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Sensor.cs
      • Layout registration in InputManager.cs
      • Platform matchers in AndroidSupport.cs and iOSSupport.cs
      • Unity Remote integration in UnityRemoteSupport.cs
      • Test suites in CoreTests_Devices.cs and UnityRemoteTests.cs

🤖 Helpful? 👍/👎

Comment thread Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/OrientationControl.cs Outdated
Comment thread Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Sensor.cs Outdated
Comment thread Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/iOS/iOSSupport.cs Outdated
Comment thread Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs Outdated
K-Tone and others added 2 commits August 17, 2026 14:10
Review feedback (Morgan):
- Rename OrientationControl -> DeviceOrientationControl and its control
  layout "Orientation" -> "DeviceOrientation" (registration + the state
  field's layout=, kept in sync), plus the device layout displayName.
- Update the migration guide (corresponding-old-new-api.md) so
  Input.deviceOrientation maps to
  DeviceOrientationSensor.current.orientation.ReadValue() instead of "No
  corresponding API yet", add the sensor to the supported-sensors reference,
  and add a CHANGELOG entry (u-pr[bot] P2).

Note: the iOS/Android layout matchers still use .WithDeviceClass("Orientation")
- that string matches the native device descriptor type, a different
identifier from the control layout, so it is intentionally left unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…o "DeviceOrientation"

Review feedback (Morgan): tidy the internal device-class token for
consistency. The iOS/Android layout matchers now use
.WithDeviceClass("DeviceOrientation"), matching the native descriptor.type
change in the companion unity.git PR. WebGL/UWP match by the full layout
name directly and are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@K-Tone

K-Tone commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

@u-pr Can you check if all the reviewer comments were resolved?

@u-pr

u-pr Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Yes, all reviewer comments and suggestions have been addressed and resolved:

  1. Accidental manifest dependency (Packages/manifest.json)u-pr[bot]

    • Status: Resolved. Packages/manifest.json was reverted and is no longer part of the changes.
  2. Rename sensor to DeviceOrientationSensor (Sensor.cs)MorganHoarau

    • Status: Resolved. Renamed to DeviceOrientationSensor across all implementations, layouts, platform integrations, documentation, and tests.
  3. Rename control to DeviceOrientationControl (OrientationControl.cs)MorganHoarau

    • Status: Resolved. The file was renamed to DeviceOrientationControl.cs and the class to DeviceOrientationControl.
  4. Update layout registration in InputManager.csMorganHoarau

    • Status: Resolved. Updated to RegisterControlLayout("DeviceOrientation", typeof(DeviceOrientationControl));.
  5. Update displayName in Sensor.csMorganHoarau

    • Status: Resolved. Updated to [InputControlLayout(stateType = typeof(DeviceOrientationState), displayName = "DeviceOrientation")] on DeviceOrientationSensor.
  6. Android and iOS device matchersMorganHoarau

    • Status: Resolved. Both AndroidSupport.cs and iOSSupport.cs now use .WithDeviceClass("DeviceOrientation") in lockstep with the companion native changes.
  7. Discussion items (Unity Remote support & module-side migration note)MorganHoarau

    • Status: Addressed in thread discussions (Unity Remote context clarified and tests included; long-term module-side migration noted for future work).

🤖 Helpful? 👍/👎

@ekcoh ekcoh 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.

Looks good, lest some questions/reflections - basically happy to approve but want to also look at the native part before approval.

/// A control reading a <see cref="DeviceOrientation"/> value.
/// </summary>
/// <remarks>
/// This is used by <see cref="DeviceOrientationSensor"/> to report the physical orientation of the device

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.

Great it provides parity, but is there any kind of definition of what the reference is? Might be good to define that - if possible - since that would be the first thing I would wonder as a dev using it.

{
public static FourCC kFormat => new FourCC('O', 'R', 'N', 'T');

// Note: unlike the other sensors this value is *not* compensated for screen orientation. It reports

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.

Would it make sense to provide compensated value as well in the future you think? Generally I would argue that is a binding property - but just curious on your perspective after working with this?

@MorganHoarau MorganHoarau Aug 18, 2026

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.

/// is a package-local enum, kept independent of the legacy input module.
/// </remarks>
/// <seealso cref="DeviceOrientationSensor"/>
public enum DeviceOrientation

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.

Maybe it's just me but I find DeviceOrientation confusing since it's a quantised orientation of the screen more than anything else. Does it translate well to non-mobile sensors - I guess this mimics Input Manager president so fine by all means - just sharing a reaction since device orientation could also be seen as a Vector3 relative to some other reference Vector3 if not quantized.

I would have suspected orientation could just be derived from the Attitude sensor as part of a binding but maybe I am wrong? At least that is how I have implemented orientation based bindings previously. How is this different from quantised Attitude sensor values? Is it due to getting corresponding enum from OS?

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.

Not sure it will cover everything, but Tomas wanted it named that way as there is also a concept of screen orientation.

This one allow for value like device face up and down.

Does it translate well to non-mobile sensors

Currently, only mobile and web do have this. for gamepad, they are fed through device extension.

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.

Its fine as-is not a strong opinion, just wanted ensure we question it critically before committing to it, e.g. if a raw device orientation Vector3 is added later - it needs a matching name as well - not blocking in anyway - just a reflection

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.

4 participants