serializedObject.FindProperty returning null

I’m writing a CustomEditor for a component and having a problem where serializedObject.FindProperty is returning null. My understanding is that FindProperty should always return a SerializableProperty which I can then access objectReferenceValue to get my object. FindProperty is returning null. Here’s my code. I want to be able to access “currentConfig” and set its value later.

Component

public class BuildConfiguration : MonoBehaviour
{
	private BuildConfig _currentConfig = new BuildConfig();
	public BuildConfig currentConfig
	{
		get
		{
			return _currentConfig;
		}
		set
		{
			_currentConfig = value;
		}
	}

	void Awake()
	{
		DontDestroyOnLoad( transform.gameObject );
	}

}

Data Type

[System.Serializable]
public class BuildConfig
{
	public string name
	{
		get;
		set;
	}
	public bool embeddedLink
	{
		get;
		set;
	}
	public string linkURL
	{
		get;
		set;
	}
	public string splashScreenPath
	{
		get;
		set;
	}
}

strong text

[CustomEditor( typeof( BuildConfiguration ) )]
public class BuildSettingsSerializer : Editor
{
	private const string DEFAULT_EXPORT_PATH = "Assets/BuildSettings/";
	private static List<BuildConfig> _items = new List<BuildConfig>();
	private int index = 0;
	private static bool _isLoaded = false;
	public override void OnInspectorGUI()
	{
		base.OnInspectorGUI();
		if( !_isLoaded || _items.Count == 0 )
			LoadConfigurations();

		Debug.Log( "target = " + serializedObject );
		if( serializedObject == null )
			return;

		BuildConfig current = null;
		var prop = serializedObject.FindProperty( "currentConfig" );
		Debug.Log( "prop = " + prop );
	}
}

If anyone can enlighten me about what I’m doing wrong and why prop is null I’d appreciate it

Unity will not serialize C# properties but fields. In your case, you can do:

var prop = serializedObject.FindProperty( "_currentConfig" );

Also note that it should be serializable to Unity, so, if you want to keep that field private, mark it with [SerializeField] like so:

[SerializeField] private BuildConfig _currentConfig = new BuildConfig();

@frarees is right. That helped me come to a conclusion to my problem.

I was trying to override the drawing of a built in class (Vertical Layout Group), and the only accessable variables from inspector fields such as Padding IS a property! (You can determine this looking for a {get; set; } in Visual Studio for example)

.

And not being able to access the field names of Unity made this difficult. How ever, I chose to attempt some standard prefixes to test my luck. And it seems that Unity runs with the following prefix (at least for this particular class):

SerializedProperty padding = serializedObject.FindProperty("m_Padding");
SerializedProperty childAlignment = serializedObject.FindProperty("m_ChildAlignment");
SerializedProperty spacing = serializedObject.FindProperty("m_Spacing");
SerializedProperty reverseArrangement = serializedObject.FindProperty("m_ReverseArrangement");