Skip to content

Commit d4dd758

Browse files
authored
FIX: Fixed custom processor display in input action asset UI after entering/exiting play mode (#1671)
* Fixed custom processor display in input asset action UI AddTypeRegistration now supports being called twice with same details, and avoids adding an alias to itself. in editor. It also warns if called twice with same named entry with a different type A new test is added which failed before this change and passes after Actions_AddingSameProcessorTwice_DoesntImpactUIHideState Another test added to check same named processor overrides the original of same name Actions_AddingSameNamedProcessorWithDifferentResult_OverridesOriginal * Updated change log * Fixed tests to run on stand alone player And updated formatting
1 parent 811e5c5 commit d4dd758

3 files changed

Lines changed: 77 additions & 3 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4310,7 +4310,6 @@ public void Actions_CanAddInteractionsToActions()
43104310
{
43114311
var gamepad = InputSystem.AddDevice<Gamepad>();
43124312

4313-
InputSystem.RegisterProcessor<ConstantVector2TestProcessor>();
43144313
var action = new InputAction(interactions: "Tap(duration=0.123)");
43154314
action.AddBinding("<Gamepad>/buttonSouth");
43164315
action.Enable();
@@ -4490,6 +4489,68 @@ public void Actions_CanAddScaleProcessor()
44904489
Assert.That(receivedValues, Has.Exactly(1).EqualTo(0.5f * 2));
44914490
}
44924491

4492+
private class ConstantFloat1TestProcessor : InputProcessor<float>
4493+
{
4494+
public override float Process(float value, InputControl control)
4495+
{
4496+
return 1.0f;
4497+
}
4498+
}
4499+
private class ConstantFloat2TestProcessor : InputProcessor<float>
4500+
{
4501+
public override float Process(float value, InputControl control)
4502+
{
4503+
return 2.0f;
4504+
}
4505+
}
4506+
4507+
#if UNITY_EDITOR
4508+
[Test]
4509+
[Category("Actions")]
4510+
public void Actions_AddingSameProcessorTwice_DoesntImpactUIHideState()
4511+
{
4512+
InputSystem.RegisterProcessor<ConstantFloat1TestProcessor>();
4513+
Assert.That(InputSystem.TryGetProcessor("ConstantFloat1Test"), Is.Not.EqualTo(null));
4514+
4515+
bool hide = InputSystem.s_Manager.processors.ShouldHideInUI("ConstantFloat1Test");
4516+
Assert.That(hide, Is.EqualTo(false));
4517+
4518+
InputSystem.RegisterProcessor<ConstantFloat1TestProcessor>();
4519+
// Check we haven't caused this to alias with itself and cause it to be hidden in the UI
4520+
hide = InputSystem.s_Manager.processors.ShouldHideInUI("ConstantFloat1Test");
4521+
Assert.That(hide, Is.EqualTo(false));
4522+
}
4523+
4524+
#endif
4525+
4526+
[Test]
4527+
[Category("Actions")]
4528+
public void Actions_AddingSameNamedProcessorWithDifferentResult_OverridesOriginal()
4529+
{
4530+
var gamepad = InputSystem.AddDevice<Gamepad>();
4531+
4532+
InputSystem.RegisterProcessor<ConstantFloat1TestProcessor>("ConstantFloatTest");
4533+
InputSystem.RegisterProcessor<ConstantFloat2TestProcessor>("ConstantFloatTest");
4534+
4535+
var action = new InputAction(processors: "ConstantFloatTest");
4536+
action.AddBinding("<Gamepad>/leftTrigger");
4537+
action.Enable();
4538+
4539+
float? receivedValue = null;
4540+
action.performed +=
4541+
ctx =>
4542+
{
4543+
Assert.That(receivedValue, Is.Null);
4544+
receivedValue = ctx.ReadValue<float>();
4545+
};
4546+
4547+
InputSystem.QueueStateEvent(gamepad, new GamepadState { leftTrigger = 0.5f });
4548+
InputSystem.Update();
4549+
4550+
Assert.That(receivedValue, Is.Not.Null);
4551+
Assert.That(receivedValue.Value, Is.EqualTo(2.0).Within(0.00001));
4552+
}
4553+
44934554
[Test]
44944555
[Category("Actions")]
44954556
public void Actions_ControlsUpdateWhenNewDeviceIsAdded()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ however, it has to be formatted properly to pass verification tests.
2020

2121
### Fixed
2222
- Fixed BindingPath String-Comparison to be culture and case insensitive (case ISXB-449).
23+
- Fixed custom processor display in the input action asset UI after entering/exiting play mode (previously they got hidden) ([case ISXB-445](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-445)).
2324

2425
## [1.5.1] - 2023-03-15
2526

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ public void AddTypeRegistration(string name, Type type)
5353
var internedName = new InternedString(name);
5454

5555
#if UNITY_EDITOR
56-
if (table.ContainsValue(type))
57-
aliases.Add(internedName);
56+
// First check if the name has already been added to the table
57+
// This allows safely calling this function multiple times with same name
58+
// and prevents adding an alias to itself
59+
Type originalType;
60+
if (table.TryGetValue(internedName, out originalType))
61+
{
62+
// We don't warn about overriding any existing name/type mapping as that was previously supported
63+
table.Remove(internedName);
64+
}
65+
else
66+
{
67+
if (table.ContainsValue(type))
68+
aliases.Add(internedName);
69+
}
5870
#endif
5971

6072
table[internedName] = type;

0 commit comments

Comments
 (0)