Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

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

Discussion in 'Extensions & OnGUI' 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
    DaiMangou likes this.
  3. DaiMangou

    DaiMangou

    Joined:
    Sep 20, 2015
    Posts:
    243