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