- Home /
Draw List of UnityEvent
Having this in the target:
List<UnityEvent> events;
How do I expose these events in a custom inspector in the same way they are exposed when UnityEvent is a serialized field with no custom inspector? All ways I tried so far seem to take to a dead end.
Hi ! Why not use UnityEvent ins$$anonymous$$d..
[SerializeField] List actions;
I REALLY meant UnityEvent. I'm editing my answer. Thank you. I know it's that easy to expose it. $$anonymous$$y question though is about obtaining the set (list or array) of UnityEvents in a custom inspector.
I see , have you looked into this thread http://answers.unity3d.com/questions/1026062/how-to-add-unityevent-using-custom-inspector.html
Answer by MichaelHardrick · Jan 31, 2017 at 02:39 PM
Hello, In your OnInspectorGUI() method try this one:
EditorGUILayout.PropertyField(YOUR_EVENTS_SERIALIZEDPROPERTY, true);
This will invoke PropertyField with this signature:
public static bool PropertyField(SerializedProperty property, bool includeChildren, params GUILayoutOption[] options);
so the second argument will do the trick.
Answer by Rs · Jan 31, 2017 at 04:51 PM
Adding to woofdcr's answer, which helped, I found this to be a nice way to expose lists of classes and structs.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
[System.Serializable]
public class MetaEvent
{
public int ID;
public UnityEvent Event;
}
[System.Serializable]
public class MetaEventSet : MonoBehaviour {
public List<MetaEvent> metaEvents;
}
And for the editor part:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MetaEventSet))]
public class MetaEventSetEditor : Editor {
public override void OnInspectorGUI()
{
MetaEventSet _target = (MetaEventSet)target;
EditorGUILayout.PropertyField(serializedObject.FindProperty("metaEvents"), true);
serializedObject.ApplyModifiedProperties();
}
}
This renders UnityEvents plus other fields nicely:
Your answer
![](https://koobas.hobune.stream/wayback/20220612105927im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why I am not able to see monodevelope.app in macOS 0 Answers
How do I build to windows when I'm using mac? 1 Answer
Track User Actions Within Unity 0 Answers
Audio stops playing after a while 0 Answers