- Home /
[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)
Answer by Maxim0101 · Nov 06, 2014 at 01:27 PM
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, 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!!
Hello, Lermy, Thank you for your fast reply! This system is interesting, but I'm searching small solution, for my own propouses, w/o big systems. Unity serialization is first reason why I don't wanna rely on such frameworks :)
Answer by Gizambica · Mar 10, 2020 at 02:01 PM
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)
Answer by DKGJames · Aug 05, 2019 at 06:02 PM
It says that EditorGUIUtility.LookLikeControls(); is obsolete, I still can't get my unity event to work.
Your answer
