2. Create a Channel and send your first Message {{ currentPage ? currentPage.title : "" }}

Create a Channel

1. Open your Player BP and do following:

With PlayerTemplate: Override SP8_Override_CanSendMessage.

Without PlayerTemplate: Edit the Interface Function SP8_CanSendMessage.

Set the Return Node to true, so everyone can send Messages into all Channels (If they are Listening to it or if the Channel is visible to everyone.

Of course you can create a variable (depending on the Channel or all Channels) and set it to true or false, depending if you want him to allow the function.

2. Open your Game State and navigate to the SP8_GameState_ChatComponent.

Inside the Details Panel you can add an Item to the Default Channels Array.

Set the Variables like the Image below and set the Default Channel Variable to the same Name.

Now we have our first Channel, which every User can send and receive Messages.

The Messages will be shown in the Color Yellow.

You change the Variables however you want!

If you set Range >= 0, the Message will only be send to People in this Range. To test this, you can set it to 1000 and send a Message close to Player and then walk away.

You will see how it looks like.

Create a Widget and receive Messages

1. Now we can create a Widget, which should include a Input Field and a Grid for the Messages.

Also you should have another Widget for the Messages itself. This one should contain three Text Widgets (Time / Name / Message).

If you are not sure how to set this up, you can open the Example Widgets inside the Directory RPG_Essentials / Example / Widgets. There you should find the Widget SP8_WBP_Chat and SP8_WBP_Chat_Text.

2. Now we should setup the Message Widget first:

  • We need to create following Variables and set Instance Editable and Expose on Spawn to true:

    • Name [Text]: Contains the Name of the Player who wrote the Message

    • Message [Text]: Contains the Message itself.

    • Name Color [Linear Color]: Which Color the Name should have.

    • Color [Linear Color]: Which Color the Message should have.

    • Time [Date Time]: When the Message was send.

  • After that we can call Event Construct and do following:

    • The first Text Widget inside the Message Widget should be set to the Time, when the Message was send (Look the Image below).

    • The second Text Widget should contain the Name of the Player with the Name Color (Look the Image below).

    • The third Text Widget should contain the Message with the Color (Look the Image below).

Of course you can create other Variables as well or customize it however you want.

3. Now we need to setup the Chat itself.

  • Create a new Variable which contains the Chat Component and listen to Message Received Dispatcher (Look the Image below). Do not forget to set the Variable on start!

  • Add to the Dispatcher a Create Event Delegate and select [Create a matching Function]. This will create a Function for you. Rename it however you want (I called it MessageReceived).

  • Now we can create the Message Widget, if we receive a Message (Look the Image below). If you are using a Scroll Box you need to use Scroll to End, so it will show the newest Message.

Now if we receive a new Message, we will add a Message Widget, which contains a Text like that:

<Time> <Name> <Message>

Inside our Chat, it will be added to the bottom of all Messages.

Send Messages from the Widget

1. Now we need to add the functionality to send Messages.

We need to Listen to the Event OnTextCommitted at the Input Field.

2. If On Text Committed we need to check if the Method used was on Enter.

If yes, we can send the Message to the Global Channel and clear the Input Field.

Now we are able to write into the Input Field and if we press Enter, we will send a Message to the Global Channel.

You do not need to check if the Text is empty, because the SendMessage Function will do that for you.

Customize the Message

If you need other Variables, which should be send to other Players on send as well, you can edit the Structure SP8_S_Message inside the Directory RPG_Essentials / Chat / Structures.

You can add whatever you want. Just do not delete the Message Variable.

{{{ content }}}