How Events/Delegates Work

I realize we have access to the source, but due to the amount of preprocessor magic involved, there isn’t much by the way of readable code as it’s all machine generated by UBT/UHT. I was hoping to get some understanding of what the various bits of “event code” are up to. I’m not especially interested in how it’s behaving during runtime (yet) but just what bits are being created when we call the various macros.

On the page…

we are presented with a baseline template of an event.

Base Class Implementation:

public:
/** Broadcasts whenever the layer changes */
DECLARE_EVENT( FLayerViewModel, FChangedEvent )
FChangedEvent& OnChanged() { return ChangedEvent; }

Derived Class Implementation:

private:
/** Broadcasts whenever the layer changes */
FChangedEvent ChangedEvent;

What is going on here? From what I can tell the macro expects an function based on the name of it’s second argument, in this case FChangedEvent, the “F” and “Event” parts get truncated and “On” gets tacked to the beginning? The function returns a reference to the AssetAddedEvent member variable which has a type defined by the 2nd argument to the template.

What is going on? What are each of these bits doing and what are they there for? What depends on them? Why does OnChangedEvent return a reference to a FChangedEvent class member? The documentation is painfully lacking.

hi, Were you able to understand what’s going on with events, if so can you please explain.