Add Observer (Function)
- C++
- Blueprint
UFUNCTION(
BlueprintCallable,
Meta = (DisplayName = "Add Observer (Function)", DefaultToSelf = "Observer", AutoCreateRefTerm = "EventClass"),
Category = "Event System")
FLES_ObserverHandle BP_AddObserver_Function(
UPARAM(Meta = (AllowAbstract = "false")) const TSubclassOf<ULES_Event>& EventClass, UObject* Observer,
const FName FunctionName, const FName Channel = NAME_None);
Parameters | |
---|---|
EventClass | The static class of the events the Observer should listen for. |
Observer | The object that will be notified when events of EventClass type are sent on the Channel. |
FunctionName | The name of the event handler function that will be called when the event is received. This function should take 1 parameter of the type of your event and return no values. |
Channel | Determines the channel the event will be sent on. Observers are notified only about the events sent on the channel they're listening on. |
Return | A handle to the newly created observer record in the Event System. You may use this handle later to remove this particular observer record from the Event System. If FunctionName is not the name of a blueprint-callable member function of the Observer, an invalid handle is returned. |
Adds the Observer to the Event System and marks it as listening for events of EventClass type, that are sent on the specified Channel. The event handler will not be called if an Event is sent and the Observer has already been garbage-collected.
Example usage:
The Observer must have a member function with name FunctionName that takes 1 parameter of EventClass type and returns no values. Below is an example of an implementation of such a function in Blueprint: