Search Unity

How to display UnityEvent widget on custom editor

Discussion in 'Editor & General Support' started by ultraaviolence, Jan 23, 2020.

  1. ultraaviolence

    ultraaviolence

    Joined:
    Mar 28, 2018
    Posts:
    3
    I need to display a unity event widget on a custom editor, cause i am making the editor for my state machine script. I have looked up the internet on the past few days and apparently the way to do this is with EditorGUILayot.PropertyFiel(), on the OnGUI() method.

    Code (CSharp):
    1.  void OnGUI()
    2.     {
    3.                  FiniteStateMachine stateMachine = Selection.activeGameObject.GetComponent<FiniteStateMachine>();
    4.  
    5.         SerializedObject serializedObject = new UnityEditor.SerializedObject(stateMachine.states[0]);
    6.         serializedObject.Update();
    7.         EditorGUILayout.PropertyField(serializedObject.FindProperty("action"), true);
    8.         serializedObject.ApplyModifiedProperties();
    9.     }
    the problem is that this causes the event to show as this weird list (wich is usable, but not suitable for my project) like the one in this picture:
    upload_2020-1-23_16-0-25.png

    and I wanted to know how to show the "regular" nicely formated event widget, like the one in this picture:
    upload_2020-1-23_16-4-44.png
     

    Attached Files: