Skip to content

Commit 2a9eee3

Browse files
FIX: Set active input handler to InputManager when package is removed (ISXB-675) (#2059)
Co-authored-by: João Freire <[email protected]>
1 parent d40a2ea commit 2a9eee3

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests.
2424
- Fixed pasting bindings into empty Input Action asset. [ISXB-1180](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1180)
2525
- Fixed missing '&' symbol in Control Scheme dropdown on Windows platform. [ISXB-1109](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1109)
2626
- Fixed icon scaling in Input Actions window.
27+
- Fixed an issue where removing the InputSystem package could lead to invalid input handling settings.
2728
- Fixed `ArgumentOutOfRangeException` when adding a new Control Scheme with any Device selected. [ISXB-1129](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1129)
2829

2930
### Changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#if UNITY_EDITOR && UNITY_2020_2_OR_NEWER
2+
using System;
3+
using System.Collections.ObjectModel;
4+
using UnityEditor;
5+
using UnityEditor.PackageManager;
6+
7+
namespace UnityEngine.InputSystem.Editor
8+
{
9+
/// <summary>
10+
/// Forces the Editor to restart if the InputSystem package is removed to activate and initialize it on the managed side.
11+
/// Automatically sets "Project Settings > Player > Active Input Handling" to "Input Manager" once the package is removed.
12+
/// </summary>
13+
internal class InputSystemPackageControl
14+
{
15+
const string packageName = "com.unity.inputsystem";
16+
17+
[InitializeOnLoadMethod]
18+
static void SubscribePackageManagerEvent()
19+
{
20+
//There's a number of cases where it might not be called, for instance if the user changed the project manifest and deleted the Library folder before opening the project
21+
UnityEditor.PackageManager.Events.registeringPackages += CheckForInputSystemPackageRemoved;
22+
}
23+
24+
private static void CheckForInputSystemPackageRemoved(PackageRegistrationEventArgs packageArgs)
25+
{
26+
if (IsInputSystemRemoved(packageArgs.removed))
27+
HandleInputSystemRemoved();
28+
}
29+
30+
private static bool IsInputSystemRemoved(ReadOnlyCollection<UnityEditor.PackageManager.PackageInfo> packages)
31+
{
32+
foreach (var package in packages)
33+
{
34+
if (package.name == packageName)
35+
return true;
36+
}
37+
return false;
38+
}
39+
40+
private static void HandleInputSystemRemoved()
41+
{
42+
//Set input handling to InputManager
43+
EditorPlayerSettingHelpers.newSystemBackendsEnabled = false;
44+
if (EditorUtility.DisplayDialog("The Unity Editor needs to be restarted", "You've removed the Input System package. This requires a restart of the Unity Editor.", "Restart the Editor", "Ignore (Not recommended)"))
45+
EditorApplication.OpenProject(Environment.CurrentDirectory);
46+
}
47+
}
48+
}
49+
#endif

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)