Skip to content

1. Declaring events

Univise edited this page Apr 28, 2017 · 2 revisions

An event is a struct that inherits from FEventBase. Every event belongs in one of these two categories:

Informing events: Called after an action has happened. Modifications to the event data will not matter because the event has already happened. Example use cases might be when a player has died, the game world has finished loading, a player joined the server, etc.

Interactive events: Called before an action is about to happen. The event's data may be modified by listeners. When all listeners are done, the event caller can evaluate the result of the event and execute its action differently. Example use cases might be when damage is about to be applied to a player (override the damage), a player is attempting to join the server (allow it or not), etc.

As you might guess, the type of event depends on the context it is called in (more on calling on another wiki page).

To declare a custom event you need to simply create another struct that inherits from FEventBase (remember to include "EventBase.h". You must make sure it is registered to Unreal's reflection system, however, as the Event Subsystem uses reflection as implementation.

When declaring events, always specify in the documentation what type of context the event is for: is it an informing or interactive event? Also, briefly note when the event is called. Below you will find a model event:

/** Interactive event: Called just before a destructible, NPC, or player takes damage. */
USTRUCT()
struct FPreDamageEntityEvent : public FEventBase
{
    GENERATED_BODY();
public:

    /** The entity that will receive a call to TakeDamage. Typically a pawn but can also be applied to destructable actors. */
    UPROPERTY()
    class AActor* ActorToDamage;

    /** The type of damage that will be set in Unreal's built-in FDamageEvent.*/
    UPROPERTY()
    class UDamageType* DamageTypeToApply;

    /** The amount of damage that will be applied to the entity.*/
    UPROPERTY()
    float DamageAmount;

    /** If true, TakeDamage will not be called - if false, it will be. */
    UPROPERTY()
    bool bIsCancelled;

};
Clone this wiki locally