microsoft/MRDesignLabs_Unity_Tools

SceneObjectField in HUXEditorUtils fails when two components of the same type are on a single game object

YoriKv opened this issue · 2 comments

https://github.com/Microsoft/MRDesignLabs_Unity_Tools/blob/ec32b17034e2950784d084f838bd2b858bdc7b23/HUX/Editor/Utility/HUXEditorUtils.cs#L236-L267

If the component type that SceneObjectField is looking for is present twice on the same object, the dropdown/popup portion of this field implementation fails and will always select the first of the two components.

This appears to be an issue with EditorGUILayout.Popup(selectedIndex, displayedOptions) ignoring duplicate entries. Solution would be to include a unique component to the string in displayedOptions, such as the index of the entry so there is never a duplicate string.

A possible solution would be to do the following:
displayedOptions[i + 1] = (i + 1).ToString() + ": " + objectsInScene[i].name + " (" + objectsInScene[i].GetType().ToString() + ")";

This uses a unique index and also includes the explicit type for some more clarity in selection, but may make the names in the dropdown a bit long.

Good catch, thank you.