First day in UnityEditor scripting and after having some success with easy stuff (adding a button and creating a [ReadOnly] attribute for variables to be shown in inspector but not be modifiable), I tried to create a dropdown, and then, the problems started.
Here is the code I use :
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(GameController), editorForChildClasses: true)]
public class GameControllerEditor : Editor
{
string[] myInputsName;
int _myIndex = 0;
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
GameController e = (GameController)target;
for (int i = 0; i < e.inputType.Length - 1; i++)
{
myInputsName[i] = e.inputType[i].name;
}
_myIndex = EditorGUILayout.Popup(_myIndex,myInputsName, EditorStyles.popup);
if (GUILayout.Button("Switch Control"))
e.SwitchControl();
}
}
inputType is an array of a custom ScriptableObject.
After compiling the code it looks okay as it show me the drop box :

First problem :
The dropdown is empty and it should have “Keyboard” in it.
Second problem :
If I focus on another asset and then I come back to it, the dropdown disapear and I got an error :

Any idea, tips to solve that ?
