Skip to content

Commit 12cb9f1

Browse files
FIX: [Port] [UUM-137448] Fixed layout merge for controls declared for several variants (#2505)
1 parent da6127d commit 12cb9f1

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎Assets/Tests/InputSystem/CoreTests_Layouts.cs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,50 @@ public void Layouts_CanMatchControlPath()
26242624
Assert.That(layout.m_Controls.Any(x => InputControlPath.MatchControlComponent(ref parsedUsagesPath, ref x)), Is.True);
26252625
}
26262626

2627+
[Test]
2628+
[Category("Layouts")]
2629+
public void Layouts_ControlDeclaredForSeveralVariants_MergesUnderEachOfThem()
2630+
{
2631+
const string jsonBase = @"
2632+
{
2633+
""name"" : ""VariantBaseCombined"",
2634+
""extend"" : ""Gamepad"",
2635+
""controls"" : [
2636+
{ ""name"" : ""custom"", ""layout"" : ""Axis"", ""variants"" : ""lefty;righty"", ""offset"" : 32 }
2637+
]
2638+
}
2639+
";
2640+
const string jsonDerived = @"
2641+
{
2642+
""name"" : ""VariantDerivedFromCombined"",
2643+
""extend"" : ""VariantBaseCombined"",
2644+
""controls"" : [
2645+
{ ""name"" : ""custom"", ""variants"" : ""lefty"", ""format"" : ""FLT"" },
2646+
{ ""name"" : ""custom"", ""variants"" : ""righty"", ""format"" : ""FLT"" }
2647+
]
2648+
}
2649+
";
2650+
2651+
InputSystem.RegisterLayout(jsonBase);
2652+
InputSystem.RegisterLayout(jsonDerived);
2653+
2654+
var layout = InputSystem.LoadLayout("VariantDerivedFromCombined");
2655+
2656+
// Both variants named in the base must merge with the derived controls and inherit
2657+
// the base's settings, not just the first one.
2658+
var lefty = layout.controls.Single(x => x.name.ToString() == "custom" &&
2659+
string.Equals(x.variants.ToString(), "lefty", StringComparison.OrdinalIgnoreCase));
2660+
var righty = layout.controls.Single(x => x.name.ToString() == "custom" &&
2661+
string.Equals(x.variants.ToString(), "righty", StringComparison.OrdinalIgnoreCase));
2662+
2663+
Assert.That(lefty.layout.ToString(), Is.EqualTo("Axis"));
2664+
Assert.That(righty.layout.ToString(), Is.EqualTo("Axis"));
2665+
Assert.That(lefty.offset, Is.EqualTo(32));
2666+
Assert.That(righty.offset, Is.EqualTo(32));
2667+
Assert.That(lefty.format, Is.EqualTo(new FourCC("FLT")));
2668+
Assert.That(righty.format, Is.EqualTo(new FourCC("FLT")));
2669+
}
2670+
26272671
[Test]
26282672
[Category("Layouts")]
26292673
[Ignore("TODO")]

‎Packages/com.unity.inputsystem/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Fixed touch input from Unity Remote 5 being ignored in Unity 6000.5 and newer. [UUM-155327](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-155327)
1414
- Fixed actions enabled during startup, for example in an Entities system's `OnCreate`, being disabled when entering Play Mode with domain reload disabled and in Player builds. [UUM-151403](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-151403)
1515
- Fixed the Player Input component Inspector not showing the action map events after the Behavior is set to Invoke Unity Events, until the GameObject was selected again. [UUM-150956](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-150956)
16+
- Fixed a control declared for several variants at once (for example `"variants" : "A;B"`) only merging with derived layouts under its first variant; derived overrides for the other variants lost the base control's layout, offset, format and usages. [UUM-160829](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-160829)
1617

1718
## [1.20.1] - 2026-10-05
1819

‎Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlLayout.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,7 @@ private static Dictionary<string, ControlItem> CreateLookupTableForControls(
14851485
foreach (var name in itemVariantArray)
14861486
{
14871487
variants?.Add(name);
1488-
key = $"{key}@{name}";
1489-
table[key] = controlItems[i];
1488+
table[$"{key}@{name}"] = controlItems[i];
14901489
}
14911490

14921491
continue;

0 commit comments

Comments
 (0)