Skip to content

Commit 2163cc1

Browse files
FIX: Modify logic to get active player settings object to work with build profiles (ISXB-1430) (#2136)
1 parent 5746c4c commit 2163cc1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ however, it has to be formatted properly to pass verification tests.
1111
## [Unreleased] - yyyy-mm-dd
1212

1313
### Fixed
14+
- Fixed a problem with the logic to get the active player settings object that cause an infinit reimport loop. [ISXB-1430](https://jira.unity3d.com/browse/ISXB-1430)
1415
- Fixed an issue where removing a newly created action in the Asset Editor would cause an exception. [UUM-95693](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-95693)
1516
- Fixed arrow key navigation of Input Actions after Action rename. [ISXB-1024](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1024)
1617
- Fixed gamepad navigation in UI Toolkit TextField when using InputSystemUIInputModule. [UUM-77364](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-77364)

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/EditorPlayerSettingHelpers.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
using System.Linq;
44
using UnityEditor;
55

6+
#if UNITY_6000_0_OR_NEWER
7+
using System.Reflection;
8+
using UnityEditor.Build.Profile;
9+
#endif
10+
611
namespace UnityEngine.InputSystem.Editor
712
{
813
internal static class EditorPlayerSettingHelpers
@@ -154,7 +159,33 @@ private static int TupleToActiveInputHandler((bool newSystemEnabled, bool oldSys
154159

155160
private static SerializedProperty GetPropertyOrNull(string name)
156161
{
162+
#if UNITY_6000_0_OR_NEWER
163+
// HOTFIX: the code below works around an issue causing an infinite reimport loop
164+
// this will be replaced by a call to an API in the editor instead of using reflection once it is available
165+
var buildProfileType = typeof(BuildProfile);
166+
var globalPlayerSettingsField = buildProfileType.GetField("s_GlobalPlayerSettings", BindingFlags.Static | BindingFlags.NonPublic);
167+
if (globalPlayerSettingsField == null)
168+
{
169+
Debug.LogError($"Could not find global player settings field in build profile when trying to get property {name}. Please try to update the Input System package.");
170+
return null;
171+
}
172+
var playerSettings = (PlayerSettings)globalPlayerSettingsField.GetValue(null);
173+
var activeBuildProfile = BuildProfile.GetActiveBuildProfile();
174+
if (activeBuildProfile != null)
175+
{
176+
var playerSettingsOverrideField = buildProfileType.GetField("m_PlayerSettings", BindingFlags.Instance | BindingFlags.NonPublic);
177+
if (playerSettingsOverrideField == null)
178+
{
179+
Debug.LogError($"Could not find player settings override field in build profile when trying to get property {name}. Please try to update the Input System package.");
180+
return null;
181+
}
182+
var playerSettingsOverride = (PlayerSettings)playerSettingsOverrideField.GetValue(activeBuildProfile);
183+
if (playerSettingsOverride != null)
184+
playerSettings = playerSettingsOverride;
185+
}
186+
#else
157187
var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>().FirstOrDefault();
188+
#endif
158189
if (playerSettings == null)
159190
return null;
160191
var playerSettingsObject = new SerializedObject(playerSettings);

0 commit comments

Comments
 (0)