Skip to content

Commit 4f0179e

Browse files
authored
FIX: Parameter editor not reacting to changes to InputSettings (#2130)
1 parent c1222db commit 4f0179e

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ however, it has to be formatted properly to pass verification tests.
2727
- Pinned Touch Samples sample package dependencies to avoid errors with Cinemachine 3.x and Probuilder 6.x. [ISXB-1245](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1245)
2828
- Fixed issue where a binding path is sometimes not saved when chosen from the binding path picker. [ISXB-1221](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1221)
2929
- Fixed an issue where dropdown menu for Path in Input Actions Editor could not be selected from any button position. [ISXB-1309](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1309)
30+
- Fixed an issue where changing Input System default parameter settings with the editor open would result in changes in the editor. [ISXB-1351](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1351)
3031

3132
## [1.12.0] - 2025-01-15
3233

Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ public void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
238238
value = m_DefaultInitializedValue;
239239

240240
var container = new VisualElement();
241-
var settingsContainer = new VisualElement { style = { flexDirection = FlexDirection.Row } };
241+
container.RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
242+
container.RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
242243

244+
var settingsContainer = new VisualElement { style = { flexDirection = FlexDirection.Row } };
243245

244246
m_FloatField = new FloatField(m_ValueLabel.text) { value = value };
245247
m_FloatField.Q("unity-text-input").AddToClassList("float-field");
@@ -260,7 +262,6 @@ public void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
260262
m_DefaultToggle.RegisterValueChangedCallback(evt => ToggleUseDefaultValue(evt, onChangedCallback));
261263
m_DefaultToggle.Q<Label>().style.minWidth = new StyleLength(StyleKeyword.Auto);
262264

263-
264265
var buttonContainer = new VisualElement
265266
{
266267
style =
@@ -286,22 +287,28 @@ public void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
286287
root.Add(container);
287288
}
288289

289-
private void ChangeSettingValue(ChangeEvent<float> evt)
290+
private void OnAttachToPanel(AttachToPanelEvent evt)
291+
{ // Monitor changes to settings for as long as the panel is attached to a visual tree
292+
InputSystem.onSettingsChange += InputSystemOnSettingsChange;
293+
}
294+
295+
private void OnDetachFromPanel(DetachFromPanelEvent evt)
296+
{ // Stop monitoring changes to settings when panel is no longer part of a visual tree
297+
InputSystem.onSettingsChange -= InputSystemOnSettingsChange;
298+
}
299+
300+
private void InputSystemOnSettingsChange()
290301
{
291-
if (m_UseDefaultValue) return;
302+
// Default value may change at any point settings are modified so fetch current default value
303+
// if currently configured to display default value and having default coming from settings.
304+
if (m_FloatField != null && m_UseDefaultValue && m_DefaultComesFromInputSettings)
305+
m_FloatField.value = m_GetDefaultValue();
306+
}
292307

293-
// ReSharper disable once CompareOfFloatsByEqualityOperator
294-
if (evt.newValue == m_DefaultInitializedValue)
295-
{
296-
// If user sets a value that is equal to default initialized, change value slightly so it doesn't pass potential default checks.
297-
////TODO: refactor all of this to use tri-state values instead, there is no obvious float value that we can use as default (well maybe NaN),
298-
////so instead it would be better to have a separate bool to show if value is present or not.
299-
m_SetValue(evt.newValue + float.Epsilon);
300-
}
301-
else
302-
{
303-
m_SetValue(evt.newValue);
304-
}
308+
private void ChangeSettingValue(ChangeEvent<float> evt)
309+
{
310+
if (!m_UseDefaultValue)
311+
SetValue(evt.newValue);
305312
}
306313

307314
private void OnEditEnd(Action onChangedCallback)
@@ -322,6 +329,21 @@ private void ToggleUseDefaultValue(ChangeEvent<bool> evt, Action onChangedCallba
322329
}
323330

324331
#endif
332+
private void SetValue(float newValue)
333+
{
334+
// ReSharper disable once CompareOfFloatsByEqualityOperator
335+
if (newValue == m_DefaultInitializedValue)
336+
{
337+
// If user sets a value that is equal to default initialized, change value slightly so it doesn't pass potential default checks.
338+
////TODO: refactor all of this to use tri-state values instead, there is no obvious float value that we can use as default (well maybe NaN),
339+
////so instead it would be better to have a separate bool to show if value is present or not.
340+
m_SetValue(newValue + float.Epsilon);
341+
}
342+
else
343+
{
344+
m_SetValue(newValue);
345+
}
346+
}
325347

326348
public void OnGUI()
327349
{
@@ -342,16 +364,7 @@ public void OnGUI()
342364
////TODO: use slider rather than float field
343365
var newValue = EditorGUILayout.FloatField(m_ValueLabel, value, GUILayout.ExpandWidth(false));
344366
if (!m_UseDefaultValue)
345-
{
346-
// ReSharper disable once CompareOfFloatsByEqualityOperator
347-
if (newValue == m_DefaultInitializedValue)
348-
// If user sets a value that is equal to default initialized, change value slightly so it doesn't pass potential default checks.
349-
////TODO: refactor all of this to use tri-state values instead, there is no obvious float value that we can use as default (well maybe NaN),
350-
////so instead it would be better to have a separate bool to show if value is present or not.
351-
m_SetValue(newValue + float.Epsilon);
352-
else
353-
m_SetValue(newValue);
354-
}
367+
SetValue(newValue);
355368

356369
EditorGUI.EndDisabledGroup();
357370

0 commit comments

Comments
 (0)