Download

Can you pass an event to a function as a variable?

I’m trying to create some abstraction between functions I re-use in many programs and I’d like the ability to call a function and pass it an event to fire off under certain conditions (bind an event at runtime).

Is this not possible, or am I missing something?

Can you give a more detailed reason of why you need to do this? I might know of something that will work.

Well, I’ve had a couple use case scenarios, but I’ll give you the one I’m currently working on.

I am creating a set of components that you can add to give your characters “life”, so for example, there is a HasHealth component which gives the object “health”. I’d like to pass in an event to call when the object “dies”…

I just did some testing, and it looks like you can pass an event to a macro, but not a function (functions cannot have wildcard inputs). In my set-up, when I press a button, a macro executes the inputted event, here is a screenshot:

Untitled-1.png

As you can see, I input my delegate, and then execute the delegate after .01 seconds (0 doesn’t work). Hopefully my ugly arrows don’t bother you too much, but let me know how it works out, enjoy!

Yeah, that doesn’t work for me in this scenario.

The purpose of this is to be able to go into an object, say for example FirstPersonCharacter, click “Add Component” and then click on the “HasHealth” component which provides the basic functions for having health. I’d then like to either in the default variables section on the right hand side select an “OnDeath” event, or thru the component drag off and call a SetOnDeath function and pass it a reference to the event to bind to.

I think I have an idea of what you are getting at, and I wish you luck in the solution. I also thought about doing such a thing in my project, having components do the “heavy lifting” of things like health, shields and magical reserves. I would then have the Actor with these attached components, for example one NPC has a health component and another NPC does not. The one without the health component would never “feel pain”, would never die. There’s no health component to tell it otherwise.

While I could get it to semi-work, I was not able to find a way to actually pull that information from the owner (the one the component is attached to) of the components. To be able to use that information in such a way that I could manipulate it. That was the part that was eluding me. I still like the idea, though. I think it’s the way to go, just don’t have the knowledge yet of how to pull it off.

If you find your solution, please share. :slight_smile: