Skip to content

Commit 9dc97d8

Browse files
committed
fix using static variable hack
1 parent dbff69a commit 9dc97d8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/InputBindingPropertiesView.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static void DrawMatchingControlPaths(List<MatchingControlPath> matchingC
149149
private void DrawMatchingControlPaths()
150150
{
151151
bool controlPathUsagePresent = false;
152-
List<MatchingControlPath> matchingControlPaths = MatchingControlPath.CollectMatchingControlPaths(m_ControlPathEditor.pathProperty.stringValue, showMatchingLayouts, ref controlPathUsagePresent);
152+
List<MatchingControlPath> matchingControlPaths = MatchingControlPath.CollectMatchingControlPaths(InputControlPathEditor.pathProperty.stringValue, showMatchingLayouts, ref controlPathUsagePresent);
153153
if (matchingControlPaths == null || matchingControlPaths.Count != 0)
154154
{
155155
EditorGUILayout.BeginVertical();

Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public InputControlPathEditor(SerializedProperty pathProperty, InputControlPicke
3131
if (pathProperty == null)
3232
throw new ArgumentNullException(nameof(pathProperty));
3333
Debug.Log($"New Path Property on {pathProperty.serializedObject.targetObject.GetInstanceID()}");
34-
this.pathProperty = pathProperty;
34+
InputControlPathEditor.pathProperty = pathProperty;
3535
this.onModified = onModified;
3636
m_PickerState = pickerState ?? new InputControlPickerState();
3737
m_PathLabel = label ?? new GUIContent(pathProperty.displayName, pathProperty.GetTooltip());
@@ -159,8 +159,8 @@ private void ShowDropdown(Rect rect, Action modifiedCallback)
159159
m_PickerState,
160160
path =>
161161
{
162-
Debug.Log($"Saving path to property on {pathProperty.serializedObject.targetObject.GetInstanceID()}");
163162
pathProperty.stringValue = path;
163+
pathProperty.serializedObject.ApplyModifiedProperties();
164164
m_PickerState.manualPathEditMode = false;
165165
modifiedCallback();
166166
});
@@ -183,7 +183,12 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property)
183183
SetExpectedControlLayout(attribute.layout);
184184
}
185185

186-
public SerializedProperty pathProperty { get; }
186+
// This static variable is a hack. Because the editor is rebuilt at unpredictable times with a new serializedObject, we need to keep updating
187+
// This variable with most up to date serializedProperty, so that the picker dropdown can access the correct serializedProperty.
188+
// The picker dropdown is a separate window and does not have access to the changed serializedObject reference.
189+
// This is a temporary solution until the InputControlPathEditor is converted to UITK or there is away to have a stable, persistent serializedObject backing this editor.
190+
// This property will be shared among multiple asset editor windows.
191+
public static SerializedProperty pathProperty { get; private set; }
187192
public Action onModified { get; }
188193

189194
private GUIContent m_PathLabel;

0 commit comments

Comments
 (0)