Skip to content

FIX: Correct north, east, south, west bindings for Switch Pro Controller to match the physical layout of the device #2208

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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

vallerieknight-unity
Copy link
Member

@vallerieknight-unity vallerieknight-unity commented Jul 29, 2025

Description

  • Adds a new device for iOS, such that we can correctly parse the state of the A button as buttonEast (and so on)
  • Corrects Desktop HID device's aButton, bButton, zButton, yButton binding to be correct for the Switch Pro Controller

Testing status & QA

  • Tested locally on iOS 18.5 (for iOS, connected via Bluetooth) and macOS 15.5 (for Desktop, connected Bluetooth + USB)
  • Added new tests to check for Nintendo state being parsed correctly

Overall Product Risks

iOS : This could break som projects if the project already has mitigations for this behaviour, but, the behaviour was incorrect previously, and customers in this position can disable the new device.

Standalone: Less likely to break customer projects, but, could break UI / tutorialisation if a user is assuming .aButton is always the same as button south. Happy to revert the standalone change, but if you are a Unity employee, please reach out on Slack as I can explain this decision making process further.

  • Complexity: Low
  • Halo Effect: Low

Comments to reviewers

See above notes on some potential upgrade pain - would be good to have some feedback / thoughts from other folks on both of these risks.

Checklist

Before review:

  • [ X ] 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".
  • [ X ] Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • [ X ] 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.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@vallerieknight-unity vallerieknight-unity changed the title Nintendo pro controller fixes ios hid [NEED-JIRA] Improve support for Switch Pro Controller [HID desktop + iOS] Jul 29, 2025
@vallerieknight-unity vallerieknight-unity changed the title [NEED-JIRA] Improve support for Switch Pro Controller [HID desktop + iOS] [ISXB-TODO] Improve support for Switch Pro Controller [HID desktop + iOS] Jul 29, 2025
@codecov-github-com
Copy link

codecov-github-com bot commented Jul 29, 2025

Codecov Report

Attention: Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ystem/InputSystem/Plugins/iOS/IOSGameController.cs 93.33% 1 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2208      +/-   ##
===========================================
+ Coverage    68.11%   68.12%   +0.01%     
===========================================
  Files          367      367              
  Lines        53603    53623      +20     
===========================================
+ Hits         36512    36531      +19     
- Misses       17091    17092       +1     
Flag Coverage Δ
mac_2021.3_pkg 5.40% <0.00%> (-0.01%) ⬇️
mac_2021.3_project 70.37% <95.00%> (+0.01%) ⬆️
mac_2022.3_pkg 5.18% <0.00%> (-0.01%) ⬇️
mac_2022.3_project 65.24% <95.00%> (+0.01%) ⬆️
mac_6000.0_pkg 5.19% <0.00%> (-0.01%) ⬇️
mac_6000.0_project 68.04% <95.00%> (+0.01%) ⬆️
mac_6000.1_pkg 5.19% <0.00%> (-0.01%) ⬇️
mac_6000.1_project 68.05% <95.00%> (+0.02%) ⬆️
mac_6000.2_pkg 5.19% <0.00%> (-0.01%) ⬇️
mac_6000.2_project 68.03% <95.00%> (-0.01%) ⬇️
mac_trunk_pkg 5.19% <0.00%> (-0.01%) ⬇️
mac_trunk_project 68.03% <95.00%> (+0.01%) ⬆️
win_2021.3_pkg 5.41% <0.00%> (-0.01%) ⬇️
win_2022.3_pkg 5.18% <0.00%> (-0.01%) ⬇️
win_2022.3_project 65.31% <95.00%> (+0.01%) ⬆️
win_6000.0_pkg 5.19% <0.00%> (-0.01%) ⬇️
win_6000.0_project 68.11% <95.00%> (+0.01%) ⬆️
win_6000.1_pkg 5.19% <0.00%> (-0.01%) ⬇️
win_6000.1_project 68.11% <95.00%> (+0.01%) ⬆️
win_6000.2_pkg 5.19% <0.00%> (-0.01%) ⬇️
win_6000.2_project 68.10% <95.00%> (+0.01%) ⬆️
win_trunk_pkg 5.19% <0.00%> (-0.01%) ⬇️
win_trunk_project 68.10% <95.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
...m.unity.inputsystem/InputSystem/Devices/Gamepad.cs 93.16% <100.00%> (+0.24%) ⬆️
...putSystem/Plugins/Switch/SwitchProControllerHID.cs 29.43% <ø> (ø)
....inputsystem/InputSystem/Plugins/iOS/iOSSupport.cs 75.00% <100.00%> (+1.66%) ⬆️
...ystem/InputSystem/Plugins/iOS/IOSGameController.cs 93.33% <93.33%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vallerieknight-unity vallerieknight-unity changed the title [ISXB-TODO] Improve support for Switch Pro Controller [HID desktop + iOS] [FIX] Correct north, east, south, west bindings for Switch Pro Controller to match the physical layout of the device Jul 31, 2025
@vallerieknight-unity vallerieknight-unity changed the title [FIX] Correct north, east, south, west bindings for Switch Pro Controller to match the physical layout of the device FIX: Correct north, east, south, west bindings for Switch Pro Controller to match the physical layout of the device Jul 31, 2025
@vallerieknight-unity vallerieknight-unity marked this pull request as ready for review July 31, 2025 11:36
@vallerieknight-unity
Copy link
Member Author

vallerieknight-unity commented Jul 31, 2025

iOS CI issues appear to be instabilities also occurring on head of develop; will trigger reruns periodically. Linux issues appear to be pvp-sign.

Comment on lines 158 to 185
/// <summary>
/// A Button for a Nintendo Switch Pro Controller.
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
/// The gamepad class will return the state of buttonSouth, whereas this class returns the state of buttonEast
/// </summary>
public new ButtonControl aButton => buttonEast;

/// <summary>
/// A Button for a Nintendo Switch Pro Controller.
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
/// The gamepad class will return the state of buttonEast, whereas this class returns the state of buttonSouth
/// </summary>
public new ButtonControl bButton => buttonSouth;

/// <summary>
/// A Button for a Nintendo Switch Pro Controller.
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
/// The gamepad class will return the state of buttonNorth, whereas this class returns the state of buttonWest
/// </summary>
public new ButtonControl yButton => buttonWest;

/// <summary>
/// A Button for a Nintendo Switch Pro Controller.
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
/// The gamepad class will return the state of buttonWest, whereas this class returns the state of buttonNorth
/// </summary>
public new ButtonControl xButton => buttonNorth;

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a change impacting all platforms, right? The Changelog gives the idea we only changed this for iOS,.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that's a good point; thanks! If it sounds OK to you, I can add a new changelog item to reference the aliases being corrected and state that this is updated for both iOS and standalone.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just added new changelog item to help clear up why this was fixed here. If you think this should be a second PR, let me know - I combined it together, just as the actual issue there impacts both iOS & Standalone :)

Comment on lines 200 to 204
/// A Switch Pro Controller connected to an iOS device.
/// If you use InputSystem.GetDevice, you must query for this class rather than Gamepad in order for aButton, bButton, yButton and xButton to be correct
/// </summary>
[InputControlLayout(stateType = typeof(iOSGameControllerStateSwappedFaceButtons), displayName = "iOS Switch Pro Controller Gamepad")]
public class SwitchProControlleriOS : Gamepad
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a new state? I wonder if we could actually create a similar pattern of what we do here

Because the remapping seems to be done below, as we already did in SwitchProControllerHID.cs.

Maybe we would need to create a SwitchProController class. Which would be inherited by SwitchProControllerHID and SwitchProControlleriOS.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, if you query buttonSouth, you'll get the A button's state, despite the fact buttonSouth is on the east on a Pro Controller. The new state maps this all correctly, such that buttonSouth will actually return the south face button.

The changes below are intended for situations when you want a button by label, regardless of where it is on the controller (e.g. some users will query this, and their UI in a tutorial will show "Press (A)").

If it makes this easier to land currently, I can split the changes to update aButton => buttonEast and friends into a new PR. This PR would then only focus on getting in the new state that rotates around the buttons for the Pro Controller.

Also agreed on the SwitchProController class as a root class; I'm just about to log off for the weekend, so I can make that change on Monday.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just pushed change that adds new SwitchProController device :)

Copy link

@Pillmatic Pillmatic Aug 6, 2025

Choose a reason for hiding this comment

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

@vallerieknight-unity asking a lot here but a refactor like the SwitchProController for DualSense, DualShock, Xbox etc. is also much needed. We have so much boiler plate code as we otherwise get errors that specific controller features are not available on platform XY. We would expect that this is handled by the input system with an overall class per controller. Then if feature XY is not available on target XY it just does not perform the action and does not throw compile errors (e.g., PlayStation light bar). The same goes for creating actions and having to manually add targets to it due to different controller classes per platform. See the attached action we have for the select button on controllers to open a journal. You will notice we need several of the same controllers in there to make it work on all platforms the controller is used. Would bring a huge QoL improvement to using the input system.

action_example

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