Skip to content

Commit e71da8a

Browse files
author
Rene Damm
authored
FIX: JSON read changing empty binding path to null (case 1231968, #1237).
1 parent 3aeaf38 commit e71da8a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,12 +2679,17 @@ public void Actions_CanConvertActionMapToAndFromJson()
26792679
//Give action maps stable internal names (just like actions)
26802680
var map = new InputActionMap("test");
26812681

2682-
map.AddAction(name: "action1", expectedControlLayout: "Button", binding: "/gamepad/leftStick")
2682+
var action1 = map.AddAction(name: "action1", expectedControlLayout: "Button", binding: "/gamepad/leftStick");
2683+
action1
26832684
.AddBinding("/gamepad/rightStick")
26842685
.WithGroup("group")
26852686
.WithProcessor("deadzone");
26862687
map.AddAction(name: "action2", binding: "/gamepad/buttonSouth", interactions: "tap,slowTap(duration=0.1)");
26872688

2689+
// Add binding with an empty path and make sure we persist that correctly.
2690+
// https://fogbugz.unity3d.com/f/cases/1231968/
2691+
action1.AddBinding("");
2692+
26882693
var json = map.ToJson();
26892694
var maps = InputActionMap.FromJson(json);
26902695

@@ -2698,8 +2703,12 @@ public void Actions_CanConvertActionMapToAndFromJson()
26982703
Assert.That(maps[0].actions[1].id, Is.EqualTo(map["action2"].id));
26992704
Assert.That(maps[0].actions[0].expectedControlType, Is.EqualTo("Button"));
27002705
Assert.That(maps[0].actions[1].expectedControlType, Is.Null);
2701-
Assert.That(maps[0].actions[0].bindings, Has.Count.EqualTo(2));
2706+
Assert.That(maps[0].actions[0].bindings, Has.Count.EqualTo(3));
27022707
Assert.That(maps[0].actions[1].bindings, Has.Count.EqualTo(1));
2708+
Assert.That(maps[0].actions[0].bindings[0].path, Is.EqualTo("/gamepad/leftStick"));
2709+
Assert.That(maps[0].actions[0].bindings[1].path, Is.EqualTo("/gamepad/rightStick"));
2710+
Assert.That(maps[0].actions[0].bindings[2].path, Is.Not.Null);
2711+
Assert.That(maps[0].actions[0].bindings[2].path, Is.Empty);
27032712
Assert.That(maps[0].actions[0].bindings[0].groups, Is.Null);
27042713
Assert.That(maps[0].actions[0].bindings[1].groups, Is.EqualTo("group"));
27052714
Assert.That(maps[0].actions[0].bindings[0].processors, Is.Null);

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ however, it has to be formatted properly to pass verification tests.
4848
action.AddBinding("<Gamepad>/button*"); // Will only receive buttonWest, buttonEast, and buttonNorth.
4949
```
5050
* This also means that `InputAction.controls` will now only contain any control at most once.
51+
- Fixed JSON serialization of action maps not preserving empty binding paths ([case 1231968](https://issuetracker.unity3d.com/issues/cloning-actionmap-through-json-converts-empty-paths-to-null-which-is-not-allowed)).
5152

5253
### Added
5354

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ public InputBinding ToBinding()
12591259
{
12601260
name = string.IsNullOrEmpty(name) ? null : name,
12611261
m_Id = string.IsNullOrEmpty(id) ? null : id,
1262-
path = string.IsNullOrEmpty(path) ? null : path,
1262+
path = path,
12631263
action = string.IsNullOrEmpty(action) ? null : action,
12641264
interactions = string.IsNullOrEmpty(interactions) ? null : interactions,
12651265
processors = string.IsNullOrEmpty(processors) ? null : processors,

0 commit comments

Comments
 (0)