- Home /
 
 
               Question by 
               kannan21 · Jan 27, 2014 at 12:59 PM · 
                editorserializedpropertycustomeditorserializedobjectoninspectorgui  
              
 
              How to get fields of a custom script through SerializedProperty.FindPropertyRelative?
 public class Achievement 
 {
     public string description;
     public bool status;
 }
 
 public class AchievementsManager : MonoBehaviour 
 {
         public Achievement  achievements;
 }
 //////////////////////////////////////
 [CustomEditor (typeof(AchievementsManager))]
 public class AchievementsEditor : Editor 
 {       SerializedObject m_object;
         SerializedProperty dataPath;
 public void OnEnable () 
 {
     m_object = new SerializedObject(target);
     dataPath = m_object.FindProperty("achievements");
 }
 public override void OnInspectorGUI ()
 {
     m_object.Update();
 \\\\I want to display the descrption and status values of the achievement class. But it always returns null. But it is not null i have added values to it.\\\\\\\\\\\\\
 
         SerializedProperty des = aDataPath.FindPropertyRelative("description");
     SerializedProperty status = aDataPath.FindPropertyRelative("status");
     EditorGUILayout.PropertyField(des);
     EditorGUILayout.PropertyField(status);
 }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by VoxelBoy · Jan 28, 2014 at 02:37 PM
You need to mark your Achievement class as System.Serializable.
Like this:
 [System.Serializable]
 public class Achievement
 {
    public string description;
    public bool status;
 }
 
              Correct. also worth noting that if you do a sp.FindPropertyRelative - sp has to reference a regular class, not an $$anonymous$$B, see here.
Your answer