- Home /
The question is answered, right answer was accepted
How to expose UnityEvent in editor?
if I do this
public UnityEvent myEvent;
it exposes it in the editor nicely. However.
public UnityEvent<float> myFloatEvent;
does not get exposed. It claims in the lacking documentation that I should override this? I dont understand.
Answer by Helical · Nov 29, 2014 at 06:37 PM
I have found the way.
first you have to define your own event type (which is just a basic public class). however the custom event type must inherit from UnityEvent, like so.
[System.Serializable]
public class myFloatEvent : UnityEvent<float>{}
then you can make variables from it, like so.
[SerializeField]
public myFloatEvent onChangeEvent;
then you can set it in the editor
and the last step is to actually Invoke it in your custom code, which was the entire purpose of it.
onChangeEvent.Invoke(newValue);
Spent a lot of time looking for a generic answer! Found out it's actually really simple:
public UnityEvent myEvent;// exposes event to the inspector //this will act just like the UI Button.OnClick in the inspector
void Some$$anonymous$$ethod() { myEvent.Invoke(); //call the event from the inspector }
Yes, you got the setText function added to the UnityEvent but is this setText a function without arguments? Because the event is UnityEvent here??
Follow this Question
Related Questions
How do I repaint/refresh/focus without calling Key Events multiple times? 1 Answer
check if 'B' key is being pressed while clicking in Editor window 3 Answers
How to add UnityEvent using Custom Inspector? 1 Answer
event sequencing 1 Answer
Event.current.Use makes GUI disapear ONLY in standalone 2 Answers