Skip to content

Commit bbdb187

Browse files
fix logic to get active platform settings object to work with build profiles
1 parent 4f0179e commit bbdb187

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 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,23 @@ 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+
var playerSettings = (PlayerSettings)globalPlayerSettingsField.GetValue(null);
168+
var activeBuildProfile = BuildProfile.GetActiveBuildProfile();
169+
if (activeBuildProfile != null)
170+
{
171+
var playerSettingsOverrideField = buildProfileType.GetField("m_PlayerSettings", BindingFlags.Instance | BindingFlags.NonPublic);
172+
var playerSettingsOverride = (PlayerSettings)playerSettingsOverrideField.GetValue(activeBuildProfile);
173+
if (playerSettingsOverride != null)
174+
playerSettings = playerSettingsOverride;
175+
}
176+
#else
157177
var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>().FirstOrDefault();
178+
#endif
158179
if (playerSettings == null)
159180
return null;
160181
var playerSettingsObject = new SerializedObject(playerSettings);

0 commit comments

Comments
 (0)