---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/send-receive
title: Send and receive messages
updated_at: 2026-05-29T11:08:50.419Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Send and receive messages

##### Usage in Blueprints and C++

You can use PubNub's functionality via Blueprints or directly in C++ code.

* In Blueprints, you can access PubNub from any Widget or Actor. Start by [initializing chat](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/configuration#initialize-pubnub-chat) using `InitChat` on `UPubnubChatSubsystem`. Afterwards, you can use the returned `UPubnubChat` object reference to call all Chat SDK functions.

:::warning Blueprint functions
The Blueprints provided in the documentation show how you can structure your application and may contain utility methods and elements like buttons that are not part of the Unreal Chat SDK and are meant to serve as guidance.
:::

* In C++, you can use UPubnubChatSubsystem as any other Game Instance Subsystem. #include "Kismet/GameplayStatics.h" #include "Engine/GameInstance.h" #include "PubnubChatSubsystem.h" // ACTION REQUIRED: Replace ASample_ChatSubsystem with name of your Actor class void ASample_ChatSubsystem::InitChatSample() { // Get PubnubChatSubsystem from GameInstance UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this); UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>(); // Initialize Chat - InitChat may fail under some conditions so make sure to check the Result for errors before using the Chat FPubnubChatInitChatResult InitChatResult = PubnubChatSubsystem->InitChat(TEXT("demo"), TEXT("demo"), TEXT("Player_001")); UPubnubChat* PubnubChat = InitChatResult.Chat; } Chat now allows you to call all Chat SDK functions, for example, Chat->GetChannel("my_channel").

:::note Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
* Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes. 1Channel->SendTextAsync("Hello", OnSendTextResponseDelegate, SendTextParams); You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatOperationResponseNative).
* Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly. 1FPubnubChatOperationResult Result = Channel->SendText("Hello", SendTextParams);
:::

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) on your keyset in the [Admin Portal](https://admin.pubnub.com/) to store messages.
:::

## Send

Use `SendText()` to send a [message](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/message) to a channel. The method handles text content, metadata, user mentions, and channel references.

### Method signature

#### C++ / Input parameters

```cpp
Channel->SendText(
    FString Message,
    FPubnubChatSendTextParams SendTextParams = FPubnubChatSendTextParams()
);
```

#### Blueprint

#### Input parameters

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| Message | FString | Yes |  | Text that you want to send to the selected channel. |
| SendTextParams | FPubnubChatSendTextParams | Optional |  | Struct providing additional parameters. |
| > StoreInHistory | bool | Optional | `true` | If `true`, the messages are stored in Message Persistence. If `StoreInHistory` is not specified, the Message Persistence configuration specified on the Admin Portal keyset is used. |
| > SendByPost | bool | Optional | `false` | When `true`, the SDK uses HTTP POST to publish the messages. The message is sent in the BODY of the request instead of the query string when HTTP GET is used. The messages are also compressed to reduce their size. |
| > Meta | FString | Optional |  | Publish additional details with the request. |

:::note Sending quoted messages
`SendText()` does not expose quoting directly. To send a quoted message, use a [MessageDraft](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts): call `MessageDraft->SetQuotedMessage(QuotedMessage)` before `Draft->Send()`.
:::

#### Output

| Type | Description |
| --- | --- |
| `FPubnubChatOperationResult` | Result of the operation. Check `Error` and `ErrorMessage` for failure. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with `ACTION REQUIRED` before running the code. Use it as a reference when working with other examples in this document.
:::

Send a text message to a channel asynchronously.

###### C++

###### Actor.h

```cpp
// blueprint.rg41gb2_
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatChannel")
void SendTextSample();
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::SendTextSample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	// Publish a text message to this channel
	Channel->SendTextAsync(TEXT("Hello"), nullptr);
}
```

###### Blueprint

## Receive

To receive messages on a given channel, you must [connect to the channel](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/channels/watch) and start listening to message events.