I have always used delegates by declaring the delegate in my class using the corresponding MACRO, then adding the delegate object to the class, and finally binding the function of the interested class, and executing the delegate when it should. But I have never had to use FDelegateHandle. Now I come across an example that uses it, and I can’t figure out why it’s used.
Hey there n_llptr!
A FDelegateHandle is essentially what the name implies, a handle on (i.e. a reference to) a delegate.
For example, consider you have a Multicast Delegate which can be bound to many functions / callbacks in many different classes. In some class A, you want to bind a function member of class A to this delegate but want to keep a reference to this “binding”. You could use this reference / handle to later unbind from the delegate, e.g. before destroying the class A instance. In this case, you could simply use a FDelegateHandle to store this reference to the “binding”.
Now for a more concrete example:
A class called “Car” has a multicast delegate which the parts of the car (e.g. class “Wheel” or class “Motor” can bind to)
What you want to achieve through these bindings is up to you, but for the sake of this example it could be something simple as, responding to the car moving. So whenever the car moves, it broadcasts to all the bindings from the multicast delegate, announcing “Hey car part, I am on the move!” The car parts then respond by having their callbacks bound to this delegate run.
When any car part gets destroyed, you want to make sure to unbind its “respond to car moving” function from the Car’s delegate. Here, you could make use of a FDelegateHandle to store a reference to the binding inside each Car Part class (e.g. class Wheel)