Event Payload

Basic Usage

The payload is used to carry additional parameters when an event is triggered. It is defined by inheriting from UDidaEventPayload.

At the time of triggering, payload parameters can be set through the node.

concept-invoke-payload

When listening, cast to the target type to retrieve payload parameters.

concept-payload-cast

Creating a Payload

If it’s necessary to instantiate a payload manually due to specific requirements, you can use the static function UDidaEventLibrary::SpawnDidaEventPayload from the event function library. Once created, use the library’s static function UDidaEventLibrary::InvokeEvent to trigger the event.

Overloading Serialization

The payload supports overloading the following two functions:

ParameterDescription
MakeStringGenerates a string based on payload data
LoadStringAssigns payload data from a string

These functions are called during RPC and TCP event transmission for encoding payload data.

By default, data is converted to a JSON string based on reflection information, but special types, such as pointers, may require custom encoding and decoding logic. Implementing these functions enables seamless network transmission of events.

Payload Recycling

To optimize payload creation overhead, a recycling mechanism for payloads is available. This is disabled by default to prevent exceptions due to incorrect recycling function implementations. If you wish to enable it, create a subclass based on UDidaEventPayloadRecyclable and implement NativeOnRecycled or K2_OnRecycled.

The payload will attempt to retrieve from the recycle pool upon creation and be recycled after the event is invoked.

Ensure proper implementation of the recycling functions to avoid call exceptions or prolonged object retention. Also, avoid using the payload after it has been recycled.