- Home /
Why is my propertydrawer being automatically disabled?
What I Am Trying To Accomplish: I have a list of objects in a custom editor and I wanted to make an area where you could enter valid arguments then hit add to add an element. I am making a special interface for this because there are spacial considerations and it is easier to think about the arguments in a spatial manner when laid out in this way.
What I Have: I have drawn it in a PropertyDrawer for a ScriptableObject (MyObject) I made. It draws fine when the scriptableobject(MyObject) variable is inside the ScriptableObject (OtherObject) but I wanted to keep all the editor stuff inside the Editor folders to keep things clean. I am aware of the #if UNITY_EDITOR #endif things. So I tried to make the SerializedObject that I draw my SerializedProperty from to be OtherObjectEditor itself. It actually draws the interface fine but it disables the controls. I suspect this has something to with the cyclic reference.
What I Wanted To Know: Is there a way to re-enable the controls? Is there a better way to do this while keeping my two conditions of Editor script seperation and the interface I want to draw? I am open to not using PropertyDrawers to draw this kind of thing but I do not know of any other way to draw it. Is there another way, all I have to do is draw popups and radio buttons so I need to control the rects they are drawn in so maybe there is?
[CustomEditor(typeof(OtherObject))]
public class OtherObjectEditor : Editor
{
[SerializeField] private MyObject _obj;
private SerializedObject _serial_obj;
private SerializedProperty _prop;
private void OnEnable()
{
_obj = ScriptableObject.CreateInstance<MyObject>();
_obj.Init();
_serial_obj = new SerializedObject(this);
_prop = _serial_obj.FindProperty("_obj");
}
private void SomeMethod()
{
//...
if (_prop != null)
{
EditorGUILayout.PropertyField(_prop);
}
//...
}
//other stuff....
}
[System.Serializable]
public class MyObject : ScriptableObject
{
[SerializeField] private int _myvariable;
//more variables and methods like this
public void Init()
{
//some intializing logic
}
}
Answer by Dankey_Kang · Jan 26, 2019 at 05:00 AM
I figured out a way to satisfy both conditions. I still don't like some of it but it works. You create one ScriptableObject that will just act as the SerializedObject and only contains a public variable holding the second ScriptableObject that will act as the SerializedProperty that the custom editor will draw the PropertyDrawer for. This isn't an elegant solution, but it works and satisfies my conditions. If anyone has any other solutions or ideas feel free to let me know because I am open to a better solution if it exists.
Your answer
Follow this Question
Related Questions
PropertyDrawer: Texture2D preview not showing up 0 Answers
How to make my own Transform inspector without using a Custom Inspector to override Transform ? 2 Answers
Custom Editor script to show non-native class in inspector 1 Answer
Edit an object in isolation quickly, as in the new Prefab Mode 0 Answers