Skip to content

Input/settings uitoolkit josep#2389

Open
josepmariapujol-unity wants to merge 12 commits intodevelopfrom
input/settings-uitoolkit-josep
Open

Input/settings uitoolkit josep#2389
josepmariapujol-unity wants to merge 12 commits intodevelopfrom
input/settings-uitoolkit-josep

Conversation

@josepmariapujol-unity
Copy link
Collaborator

Description

Please fill this section with a description what the pull request is trying to address and what changes were made.

Testing status & QA

Please describe the testing already done by you and what testing you request/recommend QA to execute. If you used or created any testing project please link them here too for QA.

Overall Product Risks

Please rate the potential complexity and halo effect from low to high for the reviewers. Note down potential risks to specific Editor branches if any.

  • Complexity:
  • Halo Effect:

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

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.

Copy link
Contributor

@u-pr u-pr bot left a comment

Choose a reason for hiding this comment

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

May require changes

This PR introduces several significant issues that could lead to crashes or broken functionality in the Input System settings UI. Specifically, there are high-importance risks related to NullReferenceException when settings assets are missing and state synchronization issues in the new UIToolkit-based UI.

Summary of findings:

  • 3 High importance bugs related to null references and stale data in UI Toolkit.
  • 1 Medium importance issue regarding a redundant UI container.
  • 3 Low importance suggestions for code cleanup, performance, and portability.

🤖 Helpful? 👍/👎

Comment on lines +102 to +111
private void DrawSupportedDevicesGUI()
{
InitializeWithCurrentSettingsIfNecessary();

using (new EditorGUI.DisabledScope(m_AvailableInputSettingsAssets.Length == 0))
{
Debug.Assert(m_Settings != null);
m_SupportedDevices.DoLayoutList();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There are two critical issues in this extracted method:

  1. NullReferenceException when no settings exist: If m_Settings is null, m_SupportedDevices will also be null, causing a NullReferenceException at m_SupportedDevices.DoLayoutList(). An early return if (m_Settings == null) return; is required.
  2. Missing Change Checks: In the fallback IMGUI path (DrawSettingsGUI(false)), m_SupportedDevices.DoLayoutList() correctly falls inside the EditorGUI.BeginChangeCheck() and EditorGUI.EndChangeCheck() blocks, triggering Apply() upon modification. However, these change checks were omitted here. Without them, modifying the Supported Devices list in UIToolkit mode will not call m_Settings.OnChange(), so the live Input System will not reload the changes.

Suggested fix:

private void DrawSupportedDevicesGUI()
{
    InitializeWithCurrentSettingsIfNecessary();
    if (m_Settings == null) return;

    using (new EditorGUI.DisabledScope(m_AvailableInputSettingsAssets.Length == 0))
    {
        m_SettingsObject.Update();
        EditorGUI.BeginChangeCheck();

        m_SupportedDevices.DoLayoutList();

        if (EditorGUI.EndChangeCheck())
            Apply();
    }
}

🤖 Helpful? 👍/👎

Comment on lines +361 to +365
m_iOSProvider.CreateGUI(lowerSectionsContainer, () =>
{
Apply();
RefreshUIToolkitHeaderState();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

If m_Settings is null (e.g., in a project where an Input Settings asset hasn't been created yet), InitializeWithCurrentSettingsIfNecessary() will exit early without instantiating m_iOSProvider. This leads to a NullReferenceException at m_iOSProvider.CreateGUI(...), completely breaking the Settings UI.

Furthermore, simply adding a null-conditional operator (m_iOSProvider?.CreateGUI) is not a complete fix. Because BuildUI() is only invoked once during OnActivate(), if a user creates a settings asset later, the iOS UI elements will remain missing from the visual tree until the settings window is reopened.

To fix this properly, InputSettingsiOSProvider should be instantiated regardless of whether m_Settings is null, and its Update(SerializedObject) method should gracefully handle a null parent. This ensures the VisualElements are always built, added to the UI tree, and then properly bound when settings are created.

🤖 Helpful? 👍/👎

Comment on lines +472 to +476
if (m_HeaderContainer == null)
return;

var hasSettings = m_SettingsObject != null;
var hasSettingsAsset = m_AvailableInputSettingsAssets != null && m_AvailableInputSettingsAssets.Length != 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Because the UIToolkit fields are manually updated by reading from SerializedProperty (e.g., property.floatValue in UpdateFloatField) rather than using data binding (Bind()), you must call m_SettingsObject?.Update(); here before reading the properties.

Without it, if the settings are modified externally (e.g., via script) or reversed via Undo/Redo, the SerializedObject will retain stale data. Consequently, RefreshUIToolkitHeaderState() will populate the UI with outdated values. Adding m_SettingsObject?.Update(); ensures the UI reflects the most recent state of the underlying InputSettings object.

🤖 Helpful? 👍/👎

HelpBoxMessageType.None);
lowerSectionsContainer.Add(m_ShortcutKeysConsumeInputsHelpBox);

m_IMGUIContainer = new IMGUIContainer(() => DrawSettingsGUI(includeUIToolkitHeader: true));
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This IMGUIContainer appears to be redundant. It calls DrawSettingsGUI(includeUIToolkitHeader: true), which skips all its internal drawing and change-checking logic due to the !includeUIToolkitHeader guards. This makes the container a no-op that still consumes resources during UI layout and repaint cycles.

🤖 Helpful? 👍/👎

}
}

private void DrawSettingsGUI(bool includeUIToolkitHeader)
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The DrawSettingsGUI method is now fragmented with multiple if (!includeUIToolkitHeader) blocks that wrap almost the entire body. Since the method effectively performs no rendering or logic when the flag is true, it would be much cleaner to use an early return at the start of the method or handle the mode switching entirely at the call sites.

🤖 Helpful? 👍/👎

return;
}

dropdown.choices = property.enumDisplayNames.ToList();
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Calling property.enumDisplayNames.ToList() in UpdateDropdownChoices creates a new list allocation every time the UI is refreshed (which happens on every settings change, undo, or redo). To reduce GC pressure, consider caching the list or only updating it if the underlying property's enum names have actually changed.

🤖 Helpful? 👍/👎

private static void OpenUpdateModeDocumentation()
{
var link = new Uri(InputSystem.kDocUrl + "/manual/Settings.html#update-mode");
System.Diagnostics.Process.Start(link.AbsoluteUri);
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Have you considered using Application.OpenURL(link.AbsoluteUri) instead of System.Diagnostics.Process.Start? Application.OpenURL is the standard Unity API for opening external links and is more portable across different editor environments (Windows, macOS, Linux).

🤖 Helpful? 👍/👎

@codecov-github-com
Copy link

codecov-github-com bot commented Mar 18, 2026

Codecov Report

Attention: Patch coverage is 0% with 321 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...putSystem/Editor/Settings/InputSettingsProvider.cs 0.00% 273 Missing ⚠️
...nputSystem/Plugins/iOS/InputSettingsiOSProvider.cs 0.00% 48 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2389      +/-   ##
===========================================
- Coverage    77.90%   77.30%   -0.61%     
===========================================
  Files          476      479       +3     
  Lines        97613    88653    -8960     
===========================================
- Hits         76048    68530    -7518     
+ Misses       21565    20123    -1442     
Flag Coverage Δ
inputsystem_MacOS_2021.3 ?
inputsystem_MacOS_2021.3_project ?
inputsystem_MacOS_2022.3 5.27% <0.00%> (-0.26%) ⬇️
inputsystem_MacOS_2022.3_project 75.19% <0.00%> (-0.21%) ⬇️
inputsystem_MacOS_6000.0 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.0_project 77.09% <0.00%> (-0.21%) ⬇️
inputsystem_MacOS_6000.2 ?
inputsystem_MacOS_6000.2_project ?
inputsystem_MacOS_6000.3 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.3_project 77.08% <0.00%> (-0.21%) ⬇️
inputsystem_MacOS_6000.4 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.4_project 77.10% <0.00%> (-0.20%) ⬇️
inputsystem_MacOS_6000.5 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.5_project 77.08% <0.00%> (-0.23%) ⬇️
inputsystem_MacOS_6000.6 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.6_project 77.09% <0.00%> (-0.22%) ⬇️
inputsystem_Ubuntu_2021.3 ?
inputsystem_Ubuntu_2021.3_project ?
inputsystem_Ubuntu_2022.3 ?
inputsystem_Ubuntu_2022.3_project 74.99% <0.00%> (-0.20%) ⬇️
inputsystem_Ubuntu_6000.0 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Ubuntu_6000.0_project 76.89% <0.00%> (-0.21%) ⬇️
inputsystem_Ubuntu_6000.2 ?
inputsystem_Ubuntu_6000.2_project ?
inputsystem_Ubuntu_6000.3 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Ubuntu_6000.3_project 76.89% <0.00%> (-0.22%) ⬇️
inputsystem_Ubuntu_6000.4 5.26% <0.00%> (-0.06%) ⬇️
inputsystem_Ubuntu_6000.4_project 76.91% <0.00%> (-0.21%) ⬇️
inputsystem_Ubuntu_6000.5 5.26% <0.00%> (-0.06%) ⬇️
inputsystem_Ubuntu_6000.5_project 76.88% <0.00%> (-0.23%) ⬇️
inputsystem_Ubuntu_6000.6 5.26% <0.00%> (-0.06%) ⬇️
inputsystem_Ubuntu_6000.6_project 76.89% <0.00%> (-0.21%) ⬇️
inputsystem_Windows_2021.3 ?
inputsystem_Windows_2021.3_project ?
inputsystem_Windows_2022.3 5.27% <0.00%> (-0.26%) ⬇️
inputsystem_Windows_2022.3_project 75.32% <0.00%> (-0.21%) ⬇️
inputsystem_Windows_6000.0 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Windows_6000.0_project 77.21% <0.00%> (-0.21%) ⬇️
inputsystem_Windows_6000.2 ?
inputsystem_Windows_6000.2_project ?
inputsystem_Windows_6000.3 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Windows_6000.3_project 77.21% <0.00%> (-0.21%) ⬇️
inputsystem_Windows_6000.4 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Windows_6000.4_project 77.22% <0.00%> (-0.21%) ⬇️
inputsystem_Windows_6000.5 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Windows_6000.5_project 77.20% <0.00%> (-0.23%) ⬇️
inputsystem_Windows_6000.6 5.25% <0.00%> (-0.06%) ⬇️
inputsystem_Windows_6000.6_project 77.22% <0.00%> (-0.21%) ⬇️
linux_2021.3_pkg ?
linux_2021.3_project ?
linux_2022.3_pkg ?
linux_2022.3_project ?
linux_6000.0_pkg ?
linux_6000.0_project ?
linux_6000.1_pkg ?
linux_6000.1_project ?
linux_6000.2_pkg ?
linux_6000.2_project ?
linux_trunk_pkg ?
linux_trunk_project ?
mac_2021.3_pkg ?
mac_2021.3_project ?
mac_2022.3_pkg ?
mac_2022.3_project ?
mac_6000.0_pkg ?
mac_6000.0_project ?
mac_6000.1_pkg ?
mac_6000.1_project ?
mac_6000.2_pkg ?
mac_6000.2_project ?
mac_trunk_pkg ?
mac_trunk_project ?
win_2021.3_pkg ?
win_2021.3_project ?
win_2022.3_pkg ?
win_2022.3_project ?
win_6000.0_pkg ?
win_6000.0_project ?
win_6000.1_pkg ?
win_6000.1_project ?
win_6000.2_pkg ?
win_6000.2_project ?
win_trunk_pkg ?
win_trunk_project ?

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

Files with missing lines Coverage Δ
...nputSystem/Plugins/iOS/InputSettingsiOSProvider.cs 0.00% <0.00%> (ø)
...putSystem/Editor/Settings/InputSettingsProvider.cs 0.80% <0.00%> (-0.82%) ⬇️

... and 69 files with indirect coverage changes

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.

1 participant