Trouble with syntax for adding function refs to event

I’m going through the pseudo-tutorial at Events | Unreal Engine Documentation , and I’ve managed to declare my event, but I’m having a lot of trouble figuring out the correct syntax to add a function to it. The declaration looks and compiles fine:

DECLARE_EVENT_OneParam(UCombat, FTickEvent, float);

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class LEARNINGPROJECT_API UCombat : public AActor
{
FTickEvent TickEvent; //Event I want a function to subscribe to

void FlowTowards(float FrameDeltaTime); //Function I want to subscribe to event
}

However, I get a compiler error when I attempt to add my function to my event in the .cpp:

void UCombat::InitializeStuff(){
	TickEvent.Add(&UCombat::FlowTowards);
}

“error C2664: ‘FDelegateHandle TBaseMulticastDelegate::Add(const TBaseDelegate &)’ : cannot convert argument 1 from ‘void (__cdecl UCombat::* )(float)’ to ‘IBaseDelegateInstance *’
Info There is no context in which this conversion is possible”

My best guess is that this is expecting me to give FloatTowards an argument when I add it to TickEvent, but I don’t understand why it would need one- the entire point of using the event-function structure is to let me run FloatTowards by calling TickEvent.Broadcast(someNumber)

Hi,

it just a guess, but in tick events float required usually for delta time, it’s time passed from last tick execute, note that in case of “events” whole blueprint system is single threaded and once tick even fired, second execution won’t apper until first ends

Right, but I’m not calling the event, I’m trying to register it like a delegate so when I call TickEvent(someDelta) (or whatever other event I make), every function(float somenumber) that I’ve registered with the event gets called. Wouldn’t that mean that I wouldn’t need to pass an argument to Add(), just the function’s address in memory?

Hi,

You have to call the correctly named Add function for what you’re trying to add, and as you’re adding a member function, you need an object to go with it. So in this case, I assume you want to add a UObject reference to the same object that’s doing the adding, so you’d use:

TickEvent.AddUObject(this, &UCombat::FlowTowards);

See ‘Binding Multi-Cast Delegates’ on this page:

Hope this helps,

Steve