Hello,
I’m using a PropertyDrawer to change how a specific type is drawn in the inspector.
So far that part works very well. It draws the name of the property and a button besides it:
The class that is being drawn:
using UnityEngine;
using System.Collections;
namespace ToastieRepublic.FX
{
[System.Serializable]
public class EffectArray : UnityEngine.Object
{
// ...
}
}
Then on my PlayerController I have:
using UnityEngine;
using System.Collections;
namespace ToastieRepublic.Characters.Player
{
[System.Serializable]
public class PlayerController : MonoBehaviour
{
// ...
public EffectArray runDust;
public EffectArray sprintStartDustLeft;
public EffectArray sprintStartDustRight;
public EffectArray sprintDust;
// ...
}
}
The result:
However, inside the PropertyDrawer’s OnGUI the objectReferenceValue is always null!
I looked around some, and it seems like objectReferenceValue is always null unless the object you’re serializing is a GameObject, or some other Unity-specific type.
Even stranger, when I try to call “SerializedProperty.serializedObject.targetObject” it returns a reference to the PlayerController that has the “runDust”, “sprintStartDustLeft”, “sprintStartDustRight” and “sprintDust” objects rather than the EffectArray instance.
This code:
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// ...
if (GUI.Button(buttonRect, "Configure"))
{
string result = string.Empty;
if (property.objectReferenceValue == null)
result = "NULL";
else
result = property.objectReferenceValue.ToString();
Debug.Log("property.objectReferenceValue: " + result);
result = property.serializedObject.targetObject.ToString();
Debug.Log("property.serializedObject.targetObject: " + result);
}
}
Prints out this:
Is this a bug? All I’m really trying to do is get a reference to the thing that is being drawn with the property drawer. I’d much rather do this than make my own Editor for the PlayerController object.