- Home /
Custom UnityEvent in Editor Window
I have searched high a low for a solution to this. All I seem to find are answers related to serialized objects which don't work in my case.
Long story short the events I am trying to "serialize" is not attached to a game object. It is a basic static field for an editor window. So pretty much I need a way to display the default inspector drawer for unity events without an object tied to it where you would use SerializedProperty to get that default functionality.
Any ideas?
public class CustomEvent : UnityEvent<MyType>
{ }
public MyWindow : EditorWindow
{
public static CustomEvent onSomething { get; } = new CustomEvent();
private void OnGUI()
{
//what do I do here to allow the user to add Subscriptions? Can't figure it out
}
}
I'd really appreciate the help thanks!
Answer by Bunny83 · Feb 23, 2020 at 09:24 AM
Your setup doesn't make much sense. Static fields are not serialized at all and won't survive an assembly reload. So letting the user assigning references to assets or even objects in the scene doesn't make sense.
Serialization in general only works on objects. Why exactly can't you use an object? Also what events do you want the user to assign? References to objects in a scene can only be stored in the scene itself.
Probably the best solution would be to use a ScriptableObject which is created in memory and stored along with the scene (if you want the user to assign references to objects in the sceme) or just use a ScriptableObject that is stored in the project as asset (in this case you can only reference other assets like prefabs or ScriptalbeObject; No references to objects in the scene are possible).
I know the normal routes which I am trying to avoid because I don't want them serialized. You gave me an idea though. Thanks for that at least.
Your answer
Follow this Question
Related Questions
can I use .rsp file to preserve static throughout edit mode and runtime? 0 Answers
Custom Editor Button Style like the one in the Hierarchy 0 Answers
Change texture import settings by script 0 Answers
How to detect if Prefab was added to the scene in Edit Mode? 1 Answer
Using EditorGUILayout in my PropertyDrawer for an attribute causes ArgumentException 1 Answer