Delegate

So if I’m correct a delegate is called whenever we do delegate.AddDynamic(this, &class::function);
right?

I’m just confused as to how it knows when to call a delegate when AddDynamic is just binding a function.

Additionally, events and delegates are esseentially the same thing then right?

Incidentally the delegate we called needs to have the same parameters as the function if I’m right? The order doesn’t matter so far as the paramters are right?

I wish there was a more indepth explanation of all this if you could show.

Edit: I’m seeing that OnComponentHit calls another delegate which is OnTakeAnyDamage. A bit confusing.

That doesn’t call the function, it merely binds it. It will be called when the delegate is broadcast.

Yes. From the docs:

Events are a specialized type of multi-cast delegate with restricted access to the Broadcast() , IsBound() , and Clear() functions.

- Multicast Delegates in Unreal Engine | Unreal Engine 5.3 Documentation

Yes.

The order matters just like any other function.

Does this code sample help?
Compiler Explorer
(note: Unreal doesn’t implement it that way, it uses its own reflection system)

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms