How to use Discord Rich Presence in Unreal Engine 4

Many modern games are adopting Discord’s Rich Presence features to display stats about your current game session to friends.

In this guide we will be working through how to use Discord Rich Presence in Unreal Engine 4 by downloading, installing and implementing Discord RPC and Rich Presence into your Unreal Engine 4 project.

discord logo

Discord has released their newer GameSDK which runs entirely using either C# for Unity or C++ for Unreal Engine. GameSDK is beyond the scope for this difficulty level which is why we will be using Discord RPC.

Adding the Discord Plugin

Downloading the Discord Plugin

Many features for Unreal Engine are built into the engine using C++ and others are compiled into a plugin. Discord has already prepared a ready made plugin for use with Unreal Engine on their GitHub page.

Method 1:

Click here to download the Discord RPC master zip.
This file is hosted on the official Discord GitHub page and not CouchLearn.com

After downloading, unzip the discord-rpc-master.zip file somewhere you can easily access it.

Method 2:

If you would like to manually clone the repository yourself click here to visit Discord’s GitHub page.

discord official GitHub page

Library Files

To download the library files necessary for compilation later on navigate to the releases section of the DiscordRPC GitHub page.

Click here to view the Releases

This file is hosted on the official Discord GitHub page and not CouchLearn.com

Find the latest release (Green text on the left) and download the discord-rpc-win.zip file.

Discord library file download

Unzip the discord-rpc-win.zip file somewhere you can easily access it.

Installing the Discord Plugin

Copying the Plugin

In our project folder we need to make sure there is a Plugins folder.

Create a new folder in your project folder named Plugins.

If you already have this you can move onto the next step.

creating the plugins folder

Included in the extracted discord RPC master folder is an example project for Unreal Engine 4.

This project has a pre-compiled Discord plugin ready for your project.

To find this plugin navigate to examples:

Discord rich presence examples from GitHub

Next, navigate to the unrealstatus folder:

Unreal Engine 4 discord example project

Finally, navigate to the Plugins folder:

Plugins folder of the Discord Rich Presence Unreal Engine 4 example project

Inside the Plugins folder is a folder named discordrpc. We need to copy and paste this folder into our own project’s Plugins folder created earlier.

The folder to copy

After copying and pasting the discordrpc folder, our project’s Plugins folder now looks like this:

DiscordRPC folder copied to your project.

Copying files to Compile the plugin

In the discord-rpc-master folder copy the include folder.

Finding the include folder and copying it

Navigate to the /ThirdParty/DiscordRpcLibrary folder in your project’s plugins folder and paste the include folder.

Pasting into the Library folder

Rename this folder to Include (make sure it has a capital I).

Renaming the include folder to Include

Create a new folder named Win64:

Creating the Win64 folder

Navigate to the /win64-dynamic/lib folder then copy and paste the discord-rpc.lib file into the Win64 folder created in the last step.

Copying the .lib file

Navigate to the /win64-dynamic/bin folder then copy and paste the discord-rpc.dll file into the Win64 folder.

copying the .dll file

Once completed your Win64 folder will look like this:

The final Win64 folder

To add Mac support for Discord to your Game click the link here for our guide for Compiling and Packaging Discord on Mac OSX.

To add Linux support for Discord to your Game click the link here for our guide for Compiling and Packaging Discord on Linux.

Compiling the Plugin

The plugin is made ready but your project doesn’t know that the files are there and hasn’t created its own files in preparation. This is why we compile the plugin on the first launch.

To compile the plugin, firstly launch your project.

As your new plugin hasn’t been compiled for your project this new prompt will show.

Press Yes to compile the plugin for your project:

Compiling the DiscordRpc plugin

The compile window will show and display the progress. This process takes a few minutes upto 10 minutes depending on the size of your project.

Unreal Engine 4 progress bar building the plugin

Enabling the Discord Plugin

Once the editor has launched, navigate to the plugins section and scroll to the bottom.

In the messaging section make sure the Discord RPC plugin is enabled.

Final plugin in the engine

If this plugin wasn’t enabled make sure to reload your editor after enabling it.

Using Discord in your Blueprints

Creating the Discord Object

In your Game Instance create a new variable named DiscordInstance and set its type to DiscordRPC object reference.

Creating the DiscordRPC object variable.

In your level blueprint, on the Begin Play event, create a Construct Object from Class node.

Constructing the discord rpc object class

For the Class node select the DiscordRpc class.

Setting the construct to the DiscordRPC object class

The outer pin is the owner of the DiscordRPC object. This should be set to your Game Instance.

Setting the outer (owner) to the game instance

Create a Cast node to your Game Instance.

Casting to the game instance

Set the DiscordInstance variable from your Game Instance to the return value of the Construct Discord RPC node.

Setting the discord instance variable to the constructed DiscordRpc class

Initializing the Connection

The Discord client needs to be notified to recieve any Rich Presence information. To notify the client, firstly create an Initialize Connection node.

Initializing the connection to discord

In the Application Id pin, copy and paste your client id from the Discord Developer Portal.

Retrieving the Client ID
Setting the Client ID into the game

Setting Discord Presence Information

Before sending the rich presence information to Discord, we need to set the variable containing the message that will be sent.

To set this create a Set Rich Presence Info node from the Discord Instance variable.

Setting the rich presence information

Right clicking and clicking break pin on the input pin of the new Set Rich Presence Info will show all the possible settings.

With this node created the entire Rich Presence data can now be set.

Full list of rich presence information

Formatting

The formatting is very specific as certain strings in the Set Rich Presence Info node are used for the Discord UI elements.

Below is the formatting from the Discord Developer page on Rich Presence.

Discord Rich Presence formatting
Image Credit: https://discordapp.com/developers/docs/rich-presence/how-to

Complete the Rich Presence information in the Set Rich Presence Info node with the formatting above.

Setting up the Timestamp (Advanced)

If your game needs to show the duration of play, follow this next section to setup the timestamp.

Discord uses the UNIX epoch system for time. Unreal Engine 4 has no built in blueprint nodes for getting the UNIX epoch time so we will have to create a few nodes to compensate for this.

Create the blueprint nodes below and connect the truncate return value to the start timestamp to count up showing duration of play since starting the game.

Creating the correct UNIX epoch timestamp

Using Images

To add an image to your Discord App, go to the Discord Developer Portal and in the Rich Presence art assets section upload the images your game requires.

Uploading images to the Discord Developer Portal

The uploaded file’s name is the key name used for the Set Rich Presence Info node. I used the Unreal Engine logo and the key is ue4logo shown above.

Adding the image key to the game

Sending information to the Discord Client

To send the rich presence information simply create a Send Presence node from the DiscordInstance variable as the target. Once you load your level the discord information will appear.

The complete Rich Presence information being sent

Here’s the final result using the settings above:

The rich presence data from the Discord client showing in game data
Label showing the discord app project name

Conclusion

Your game now has full use of Discord’s Rich Presence system in Unreal Engine 4!

Setting the presence data based on current level or your characters situation can then be used to update the client based on their current session. Just make sure to send the presence data once you have set it!

This is my largest and most comprehensive guide yet. If you found this helpful, please share with friends, other developers or on social media as more guides are coming soon.

If you want a specific guide, more guides of a specific difficulty or even different engine guides contact CouchLearn using the Contact Us link at the top of the site.

For more information on Discord Rich Presence system, click here for the full documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *