Custom UnityEvent with another layer of slots for conditions?

UnityEvents are wonderful and I’m really enjoying working with them. But I’ve hit upon a need that might be achievable and I’m not too sure.

What I’d like to make is a custom UnityEvent that has open Object/Function slots, just like UnityEvents themselves, but it gets used for checking conditions first. If the conditions in those slots are all met or not, it invokes different UnityEvents. I guess you might call it an If-Event?

For example, I might have two scripts with bools on them and one of these hypothetical 'If-Event’s. I attach it to a GameObject and in the Inspector, press the little + icon twice to create two slots and drag the two script instances in, select the bool from the drop-down list (just like a standard UnityEvent) and then tick both boxes. That’s setting the conditions.

Then below would be two UnityEvent slots called True and False, and I plug some Debug.Log functions in that read “true” or “false” respectively. When this If-Event gets invoked, it checks if both bools are set to true and if so, it fires the ‘True’ event listeners. Otherwise, it invokes the ‘False’ event.

I haven’t seen anything like this yet but I feel like it would be a really powerful tool for my team’s designers to be able to use. Does anyone know if something like this already exists and if not, if there’s a way to access those modular Object/Function slots found in UnityEvents so I could try and custom build it myself? Any insight would be greatly appreciated!

Your description is somewhat confusing. You can’t reference “variables” from a UnityEvent. To do that you would need to use a lot reflection. It would be possible to use a method that returns a bool as “condition”, however i don’t see the point why you would need to create a seperate object for that.

This sound like you actually searching for a visual scripting solution. There a plenty out there like Antares Universe VIZIO(which is free in the basic version) or the famous PlayMaker. Just have a look at this page which lists all free visual scripting extensions

If you really are interested in how the UnityEvent is implemented just have a look at the source code. That’s the corresponding PropertyDrawer for all the UnityEventBase derived types

This can help you to select a variable from any of the components in a single GameObject:

https://forum.unity.com/threads/free-field-property-and-method-inspector-like-unityevent.336784/

Hope this can help you if you still need it.