Assigning a script in custom editor

I’m trying to assign a script within a custom editor. Can this be done? And if not why haven’t they allowed this? I’ve tried EditorGUI.ObjectField, PropertyField, and DragAndDrop. I keep getting this Error : Can not convert UnityEngine.Object to . I’ve even tried using casting and other conversion methods. Any help would be greatly appreciated. Thanks :smiley:

You would do something like this:

MyClass obj;
void OnGUI(){
   obj= EditorGUILayout.ObjectField(obj, typeof(MyClass), true) as MyClass;

Note that I used EditorGUILayout.ObjectField for simplicity, the usage is similar for EditorGUI.ObjectField.

You can find more information in the documentation: