C++ Action Handlers
Receive a named UI request in C++ and return whether your game handled it.
First load the package for the player. Obtain its dispatcher with
UCalmUiLocalPlayerSubsystem::GetActionDispatcher() and use the action ID from
your project's generated schema. In the snippet, dispatcher is a reference
to that loaded dispatcher and actionId is the selected action's ID.
auto registration = dispatcher.Register(actionId, [](const calmui::Value& payload, const calmui::ActionContext& context) {
// Implement the game response here. A true return alone performs no game action.
return true;
});Keep registration and check that it is not 0. Call
dispatcher.Unregister(registration) before the owner is destroyed. Capture a
TWeakObjectPtr when the callback accesses an Unreal object that may be destroyed.
The most recently registered C++ handler for an action receives it. Registering
a native handler after the Blueprint bridge replaces that action's delivery to
Blueprint while your registration is active. Use one intended owner for the
response. Return true when handled and false when your game rejects the request.
The context identifies the local player, View, and component that sent the
request. Log() includes the result and recent requests.
For multiplayer changes that require server approval, an owning gameplay actor can
subscribe to the local FCalmUiActionReference, validate its typed payload,
send a validated Server RPC, replicate the accepted value, and write
the RepNotify result into a typed Store field. The maintained
ACalmUiReplicatedStoreSample in CalmUiSandbox demonstrates that flow. Its
owner must be the requesting client's Player Controller for the Server RPC to
be accepted. CalmUI does not send network requests automatically.