UnityEvent as a function parameter

Hello There,

I’m trying to create a flexible cutscene system where you can pass in a function as a parameter to another function to perform when certain actions are finished.

I have it working with string-based SendMessage() system, but I would ideally like to use UnityEvent instead so that I can actually select a given function instead of using strings.

I.e, instead of this:

I would get to use the drag-and-drop dropdown inspector functionality of UnityEvent, but nested inside the current UnityEvent I’m creating (mockup here):

// -- this is what I have, but its unselectable as the initial function - I'm guessing due to nested UnityEvent not being supported
public void FunctionThatHasASelectableFunctionParameter(UnityEvent functionparam)
{
    cachedfunc = functionparam;
}

Does this exist, or because its using a nested UnityEvent (a UnityEvent containing a function that has a UnityEvent parameter) is this not doable?

Thanks!

Far as I’m aware UnityEvent’s only support passing string, int, float and bool arguments to methods via the inspector. So not possible with default Unity event’s.

You may want to look at UltEvents: UltEvents | GUI Tools | Unity Asset Store

Alternatively, I’d probably look for a way without using UnityEvents. A lot more flexible things are possible these days via the use of [SerializeReference] and some custom inspector support for it.

1 Like