- Home /
Custom UnityEvent with ExposedReference object field
Hello @seant_unity ,
I need to create a Unity Event on a ScriptableObject asset so that I can create UI buttons at runtime with the callbacks of my choosing. I got my custom editor to draw the Unity Action but I obviously cant drop scene objects to the event's target field since its on an Asset file. I need to know how to replace Unity Event's Object field with a ExposedReference so that I can drag and drop scene objects. I have already created an editor with a context object (PlayableDirector in the scene). Just dont know how to modify the UnityEvent class. Any suggestions would be really helpful
Thanks
Answer by seant_unity · Sep 27, 2019 at 02:17 PM
That is not a trivial task - I wish I had a better answer. It might be possible to extend UnityEvent classes and patch the target objects and parameters with some overridden calls or serialization callbacks. UnityEvents also have a lot of custom tooling, which needs to be considered. The alternative is use a SendMessage style approach, like AnimationEvents. Or maybe an event alternative that uses the new polymorphic seralization (see here).
Your answer
Follow this Question
Related Questions
Where can I find complete list of events? 1 Answer
How to select an int/float variable from another script in the inspector? 2 Answers
How to pass UnityEvent object as method Parameter 0 Answers
How to seperate/decouple UI and player code 0 Answers
Structs are acting like Reference types for some reason. 1 Answer