On this page

Forward messages

Forward messages between channels to share information or facilitate collaboration.

icon

Usage in Blueprints and C++


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.

    1Message->ForwardAsync(Channel, OnForwardResponseDelegate);

    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 = Message->Forward(Channel);

Use Forward() on a message object or ForwardMessage() on a channel/chat object. Both produce the same result with different input parameters.

Additional info in the forwarded message

Forwarded messages include originalPublisher (original sender's user ID) and originalChannelId (source channel ID).

Method signature

  • Message->Forward()

    1Message->Forward(UPubnubChatChannel* Channel);
  • Channel->ForwardMessage()

    1Channel->ForwardMessage(UPubnubChatMessage* Message);
  • Chat->ForwardMessage()

    1Chat->ForwardMessage(
    2 UPubnubChatMessage* Message,
    3 UPubnubChatChannel* Channel
    4);
ParameterRequired in Message->Forward()Required in Channel->ForwardMessage()Required in Chat->ForwardMessage()Description
Channel
Type: UPubnubChatChannel*
Default:
n/a
Yes
No
Yes
Channel object to which you want to forward the message. You can forward a message to the same channel on which it was published or to any other.
Message
Type: UPubnubChatMessage*
Default:
n/a
No
Yes
Yes
Message object that you want to forward to the selected channel.

Output

MethodReturn type
Message->Forward()
FPubnubChatOperationResult
Channel->ForwardMessage()
FPubnubChatOperationResult
Chat->ForwardMessage()
FPubnubChatOperationResult

Sample code

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.

Forward a message to another channel asynchronously.

Actor.h
1

Actor.cpp
1

Other examples

Forward from channel

Actor.h
1

Actor.cpp
1

Forward from chat

Actor.h
1

Actor.cpp
1

Last updated on