Search Unity

[Help] Drawing UI of property of object variables property in custom Inspector ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by DaiMangouDev, Jan 21, 2019.

  1. DaiMangouDev

    DaiMangouDev

    Joined:
    Mar 26, 2014
    Posts:
    33
    Hi i am struggling to accomplish the final step which is to draw the UnityEvent myEvent property in the Inspector via the CustomEditor


    i figured that it would be much easier to visualize the code i'm working with.

    Any ideas on how i can get this working ?

    from in the Custom editor i've tried to walk through the code and fetch myEvent like this.

    Code (CSharp):
    1.   private SerializedProperty mEvent;
    2. var index = 2; // lets just get the value at index 2
    3. mEvent= serializedObject.FindProperty("ClassBData").FindPropertyRelative("ClassADataset").GetArrayElementAtIndex(index).FindPropertyRelative("myEvent");


    but FindPropertyRelative("ClassADataset") throws a null reference exception , i cant figure it out
     
  2. DaiMangouDev

    DaiMangouDev

    Joined:
    Mar 26, 2014
    Posts:
    33
    a solution


    Code (CSharp):
    1.  
    2.  private SerializedProperty myprop;
    3. private SerializedObject classC;
    4.  
    5. // whenever we pick a different valie from the ClassA list we set myprop and classC to null
    6.  
    7. if(classC == null)
    8. classC = new SerializedObject(value_FromClassAList);
    9.  
    10. if(myprop == null)
    11. myprop =  classC.FindProperty("myEvent");
    12.  
    13. classC.Update();
    14.  
    15. i then say
    16.  
    17. EditorGUILayout.PropertyField(myprop, new GUIContent("my event"));
     
    Last edited: Jan 22, 2019
    Ruchmair likes this.
  3. Ruchmair

    Ruchmair

    Joined:
    Sep 20, 2015
    Posts:
    544