Skip to content

Commit cdaa10b

Browse files
committed
Refactor ProjectWideActions to fix initialization with FEPM (ISX-1840)
- Rework the class so it operates as a Singleton (basically how it's being used) - Move actions get/set implementations from InputSystem to ProjectWideActions class * Combine functionality for tighter cohesion despite being an Editor * Update #ifefs to allow Player to access some of these members - Call EnsureInitialized() from Editor init flows to fix the actual bug Tested using ProjectWideActions sample and verified could move cube when domain reloads disabled. Ran Package tests (Edit/Play/Player) to verify no (new) failures.
1 parent 8dd1b3f commit cdaa10b

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

Assets/Tests/InputSystem/CoreTests_ProjectWideActions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ private static void CreateAndAssignProjectWideTestAsset()
3838
else
3939
EditorBuildSettings.RemoveConfigObject(name: kSavedActionsObject);
4040

41-
// Create temporary asset and assign as setting
42-
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath(kAssetPath);
43-
ProjectWideActionsBuildProvider.actionsToIncludeInPlayerBuild = asset;
4441
#endif
4542
}
4643

Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
1+
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
22

33
using System;
44
using System.Collections.Generic;
@@ -28,7 +28,6 @@ class ProjectSettingsPostprocessor : AssetPostprocessor
2828
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
2929
#else
3030
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
31-
#endif
3231
{
3332
if (!migratedInputActionAssets)
3433
{
@@ -46,19 +45,14 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del
4645
}
4746
}
4847
}
48+
}
49+
}
4950

50-
private static void MoveInputManagerAssetActionsToProjectWideInputActionAsset()
5151
{
5252
var objects = AssetDatabase.LoadAllAssetsAtPath(EditorHelpers.GetPhysicalPath(kAssetPathInputManager));
5353
if (objects == null)
5454
return;
5555

56-
var inputActionsAsset = objects.FirstOrDefault(o => o != null && o.name == kAssetNameProjectWideInputActions) as InputActionAsset;
57-
if (inputActionsAsset != default)
58-
{
59-
// Found some actions in the InputManager.asset file
60-
//
61-
string path = ProjectWideActionsAsset.kDefaultAssetPath;
6256

6357
if (File.Exists(EditorHelpers.GetPhysicalPath(path)))
6458
{
@@ -311,6 +305,7 @@ private static InputActionAsset CreateAssetAtPathFromJson(string assetPath, stri
311305
InputActionAssetManager.SaveAsset(assetPath, inputActionAsset.ToJson());
312306
return AssetDatabase.LoadAssetAtPath<InputActionAsset>(assetPath);
313307
}
308+
#endif // UNITY_EDITOR
314309
}
315310
}
316311
#endif // UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS

Packages/com.unity.inputsystem/InputSystem/InputSystem.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,9 @@ private static void DisableActions(bool triggerSetupChanged = false)
30993099
public static InputActionAsset actions
31003100
{
31013101
get => s_Manager?.actions;
3102+
{
3103+
return UnityEngine.InputSystem.Editor.ProjectWideActionsAsset.instance;
3104+
}
31023105
set
31033106
{
31043107
// Prevent this property from being assigned in play-mode.
@@ -3110,7 +3113,6 @@ public static InputActionAsset actions
31103113
var current = s_Manager.actions;
31113114
if (ReferenceEquals(current, value))
31123115
return;
3113-
31143116
var valueIsNotNull = value != null;
31153117
#if UNITY_EDITOR
31163118
// Do not allow assigning non-persistent assets (pure in-memory objects)
@@ -3127,8 +3129,6 @@ public static InputActionAsset actions
31273129

31283130
// Note that we do not enable/disable any actions until play-mode
31293131
}
3130-
}
3131-
31323132
/// <summary>
31333133
/// Event that is triggered if the instance assigned to property <see cref="actions"/> changes.
31343134
/// </summary>
@@ -3143,7 +3143,6 @@ public static event Action onActionsChange
31433143
add => s_Manager.onActionsChange += value;
31443144
remove => s_Manager.onActionsChange -= value;
31453145
}
3146-
31473146
#endif // UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
31483147

31493148
/// <summary>
@@ -3571,6 +3570,10 @@ internal static void InitializeInEditor(bool calledFromCtor, IInputRuntime runti
35713570
#endif
35723571
}
35733572

3573+
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
3574+
ProjectWideActionsAsset.EnsureInitialized();
3575+
#endif
3576+
35743577
var existingSystemObjects = Resources.FindObjectsOfTypeAll<InputSystemObject>();
35753578
if (existingSystemObjects != null && existingSystemObjects.Length > 0)
35763579
{
@@ -3627,10 +3630,8 @@ internal static void InitializeInEditor(bool calledFromCtor, IInputRuntime runti
36273630
}
36283631

36293632
Debug.Assert(settings != null);
3630-
#if UNITY_EDITOR
36313633
Debug.Assert(EditorUtility.InstanceIDToObject(settings.GetInstanceID()) != null,
36323634
"InputSettings has lost its native object");
3633-
#endif
36343635

36353636
// If native backends for new input system aren't enabled, ask user whether we should
36363637
// enable them (requires restart). We only ask once per session and don't ask when
@@ -3906,8 +3907,6 @@ internal static void PerformDefaultPluginInitialization()
39063907
#endif // UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION
39073908

39083909

3909-
3910-
39113910
#if DEVELOPMENT_BUILD || UNITY_EDITOR
39123911
/// <summary>
39133912
/// Snapshot of the state used by the input system.

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,15 +1611,14 @@ private void AssignPlayerIndex()
16111611
}
16121612
}
16131613

1614-
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
1614+
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
16151615
void Reset()
16161616
{
16171617
// Set default actions to project wide actions.
16181618
m_Actions = InputSystem.actions;
16191619
// TODO Need to monitor changes?
16201620
}
1621-
1622-
#endif
1621+
#endif
16231622

16241623
private void OnEnable()
16251624
{

Packages/com.unity.inputsystem/Tests/TestFixture/InputTestStateManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void Reset(bool enableRemoting, IInputRuntime runtime)
6565
{
6666
Profiler.BeginSample("InputSystem.Reset");
6767

68-
InputSystem.DisableActionsForTests();
68+
UnityEngine.InputSystem.Editor.ProjectWideActionsAsset.TestHook_Disable();
6969

7070
// Some devices keep globals. Get rid of them by pretending the devices
7171
// are removed.
@@ -104,7 +104,7 @@ public void Reset(bool enableRemoting, IInputRuntime runtime)
104104
InputUser.ResetGlobals();
105105
EnhancedTouchSupport.Reset();
106106

107-
InputSystem.EnableActionsForTests();
107+
UnityEngine.InputSystem.Editor.ProjectWideActionsAsset.TestHook_Enable();
108108

109109
Profiler.EndSample();
110110
}

0 commit comments

Comments
 (0)