Add a Toggle OnValueChanged Event using script

Hi All

I’d like to add an On Value Changed event through an editor script - my toggles are instantiated from a prefab but I need to add an On Value Changed event to them after they are instantiated.

I can’t seem to find this info anywhere - I just need the script equivalent of dragging a gameobject onto the Object slot and selecting the relevant public function.

Thanks!

I’m not sure there is such a thing, if there is I would love to know it too. But to add a listener to a toggle’s onValueChanged would look like this:
ToggleVar.onValueChanged.AddListener((t) => { MethodName(); });

Should that method return a Boolean? I don’t know. Where is the documentation for this sort of thing? I don’t think there is any with code examples.

Yeah I have gotten the functionality I need through the .AddListener function, but it’s all invisible - I wish we could somehow add a new entry into the event list so it’s visible!

Have you seen this? It can make events show up in the editor. UnityEvent, where have you been all my life? - Unity Engine - Unity Discussions

Yeah, I heard all about it here (as well as other stuff :P)