- Home /
EditorGUIUtility.ShowObjectPicker not working properly in unity 2021.2
I wrote the following code.
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("click") == true)
{
var controlID = EditorGUIUtility.GetControlID(FocusType.Passive);
EditorGUIUtility.ShowObjectPicker<Object>(null, false, "", controlID);
}
}
}
But in unity 2021.2.x version, I get the following error:
IndexOutOfRangeException: Index was outside the bounds of the array.
(wrapper stelemref) System.Object.virt_stelemref_sealed_class(intptr,object)
UnityEditor.ObjectSelector.Show (UnityEngine.Object obj, System.Type[] requiredTypes, UnityEngine.Object objectBeingEdited, System.Boolean allowSceneObjects, System.Collections.Generic.List`1[T] allowedInstanceIDs, System.Action`1[T] onObjectSelectorClosed, System.Action`1[T] onObjectSelectedUpdated) (at <0cde216a590a4d6fbc3d7db7ac203c5d>:0)
UnityEditor.ObjectSelector.Show (UnityEngine.Object obj, System.Type requiredType, UnityEngine.Object objectBeingEdited, System.Boolean allowSceneObjects, System.Collections.Generic.List`1[T] allowedInstanceIDs, System.Action`1[T] onObjectSelectorClosed, System.Action`1[T] onObjectSelectedUpdated) (at <0cde216a590a4d6fbc3d7db7ac203c5d>:0)
UnityEditor.EditorGUIUtility.SetupObjectSelector (UnityEngine.Object obj, System.Type objType, System.Boolean allowSceneObjects, System.String searchFilter, System.Int32 controlID) (at <0cde216a590a4d6fbc3d7db7ac203c5d>:0)
UnityEditor.EditorGUIUtility.ShowObjectPicker[T] (UnityEngine.Object obj, System.Boolean allowSceneObjects, System.String searchFilter, System.Int32 controlID) (at <0cde216a590a4d6fbc3d7db7ac203c5d>:0)
TestEditor.OnInspectorGUI () (at Assets/Editor/TestEditor.cs:16)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.b__0 () (at :0)
Is this a known bug in unity 2021.2.x? If not, am I using it wrong? Thanks for telling me how to solve it.
Comment
Your answer
Follow this Question
Related Questions
[Editor] separate AssetBundle name and variant 2 Answers
Memory Leak Adventures in Editor (3.4, lot of instantiated objects) 1 Answer
How to setup accessibility color theme on Unity editor? 1 Answer
How does the priority of a Editor menuItem change item placement? 5 Answers
EditorGUI add SortingLayer-like list to custom Editor 1 Answer