Skip to content

Commit 760a4a4

Browse files
author
Dmytro Ivanov
authored
FIX: Fixing devices not being removed when unplugged during domain reload (#1582)
1 parent aff7a19 commit 760a4a4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Assets/Tests/InputSystem/CoreTests_Editor.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,27 @@ public void TODO_Editor_DomainReload_PreservesVariantsOnDevices()
304304
Assert.Fail();
305305
}
306306

307+
[Test]
308+
[Category("Editor")]
309+
public void Editor_DomainReload_CanRemoveDevicesDuringDomainReload()
310+
{
311+
var device = InputSystem.AddDevice<Gamepad>();
312+
InputSystem.AddDevice<Keyboard>(); // just to make sure keyboard stays as-is
313+
314+
currentTime = 1;
315+
InputSystem.OnPlayModeChange(PlayModeStateChange.ExitingEditMode);
316+
317+
runtime.ReportInputDeviceRemoved(device);
318+
319+
currentTime = 2;
320+
InputSystem.OnPlayModeChange(PlayModeStateChange.EnteredPlayMode);
321+
322+
InputSystem.Update();
323+
324+
Assert.That(InputSystem.devices, Has.Count.EqualTo(1));
325+
Assert.That(InputSystem.devices[0], Is.AssignableTo<Keyboard>());
326+
}
327+
307328
[Test]
308329
[Category("Editor")]
309330
public void Editor_RestoringStateWillCleanUpEventHooks()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ however, it has to be formatted properly to pass verification tests.
1818
- Fixed Memory alignment issue with deserialized InputEventTraces that could cause infinite loops when playing back replays ([case ISXB-317](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-317)).
1919
- Fixed an InvalidOperationException when using Hold interaction, and by extension any interaction that changes to performed state after a timeout ([case ISXB-332](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-330)).
2020
- Fixed `Given object is neither an InputAction nor an InputActionMap` when using `InputActionTrace` on input action from an input action asset ([case ISXB-29](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-29)).
21+
- Fixing devices not being removed if unplugged during domain reload (entering or exiting play mode) ([case ISXB-232](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-232)).
2122

2223
## [1.4.3] - 2022-09-23
2324

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,9 @@ private unsafe void OnUpdate(InputUpdateType updateType, ref InputEventBuffer ev
29482948
// Could be that ultimately we need to issue a full reset of all devices at the beginning of
29492949
// play mode in the editor.
29502950
#if UNITY_EDITOR
2951-
if ((updateType & InputUpdateType.Editor) == 0 &&
2951+
if ((currentEventType == StateEvent.Type ||
2952+
currentEventType == DeltaStateEvent.Type) &&
2953+
(updateType & InputUpdateType.Editor) == 0 &&
29522954
InputSystem.s_SystemObject.exitEditModeTime > 0 &&
29532955
currentEventTimeInternal >= InputSystem.s_SystemObject.exitEditModeTime &&
29542956
(currentEventTimeInternal < InputSystem.s_SystemObject.enterPlayModeTime ||

0 commit comments

Comments
 (0)