[4.6] How do i draw UnityEvent in Custom Inspector

How do i draw a field of the Type UnityEvent in a Custom Inspector like in the Default Inspector
Can’t get a hold on any call to draw it or property drawer?

Can anyone help?

For anyone else necroing this thread, this is no longer necessary. Just use EditorGUILayout.PropertyField, and the event will be drawn (unity 2019.3.3f1)

3 Answers

3

Simply use “EditorGUIUtility.LookLikeControls();” before drawing property field

public override void OnInspectorGUI()
{
    base.OnInspectorGUI();
    UI_TOGGLE toggle = (UI_TOGGLE)target;
    SerializedProperty onCheck = serializedObject.FindProperty("onCheck"); // <-- UnityEvent

    EditorGUIUtility.LookLikeControls();
    EditorGUILayout.PropertyField(onCheck);

    if(GUI.changed)
    {
        serializedObject.ApplyModifiedProperties();
    }
}

Hello! by any chance did you get to draw your own parameters for passing those values to the events as well?

Hello, this code didn't work for me :( Was anyone successful in search of solution?

You can take a look at these post here about [Unity Events revamped][1], we made some really good progress on drawing Unity Events and improving their functionality, you can use the code or even perhaps make a feature contribution! :) Let us know what you think!! [1]: http://forum.unity3d.com/threads/custom-ui-event-system-revamped.353544/

For anyone else necroing this thread, this is no longer necessary. Just use EditorGUILayout.PropertyField, and the event will be drawn (unity 2019.3.3f1)

It says that EditorGUIUtility.LookLikeControls(); is obsolete, I still can’t get my unity event to work.