Skip to main content

Class HandshakeRequest<T>

A request message that carries its own reply callback, enabling synchronous request/response exchanges over the publish/subscribe event bus.

public class HandshakeRequest<T> : IMessage

Type Parameters​

NameTypeDescription
TThe type of the response data.

Inheritance​

Implements​

IMessage

Examples​

// Requester: ask for the player's tags via the event aggregator.
aggregator.Publish(new ActorTagsRequest(tags =>
{
bool isPlayer = tags.Any(t => t.name == "Player");
}));

// Responder (on the player actor):
public class MyActor : MonoBehaviour, IHandle
{
[SerializeField] private ScriptableTag[] tags;
public void Handle(ActorTagsRequest request) => request.OnResponse?.Invoke(tags);
}

Remarks​

The event bus normally delivers messages one-way: a publisher fires and forgets. When a system needs data back (e.g., querying an actor for its tags without holding a direct reference), the alternative would be publishing a reply message and subscribing to it — two round-trips through the aggregator, two subscriptions, and extra state to correlate request with response. HandshakeRequest collapses that into a single publish: the requester embeds a callback in the message, and the responder invokes it directly.

Only the first responder's invocation is meaningful because OnResponse is typically a closure capturing a single target variable. Multiple invocations would overwrite the captured value. Use a channel-scoped publish to ensure at most one responder is reached.

Constructors​

HandshakeRequest(Action<T>)​

Creates a handshake request that will deliver its result to onResponse.

public HandshakeRequest(Action<T> onResponse)

Parameters​

NameTypeDescription
onResponseAction<T>Callback invoked by the responder when a result of type T is available. May be null if the requester only wants to trigger a side effect.

Properties​

OnResponse​

The callback supplied by the requester; invoked by the responder to deliver the answer.

public Action<T> OnResponse { get; }

Property Value​

Action<T>

Remarks​

Kept read-only so responders can only call it, not replace it. A null check before invoking is good practice for callers that do not need a return value.