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 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.

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.

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.

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:

Next, navigate to the unrealstatus folder:

Finally, navigate to the Plugins folder:

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.

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

Copying files to Compile the plugin

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

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

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

Create a new folder named Win64:

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.

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

Once completed your Win64 folder will look like this:

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:

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.

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.

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.

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

For the Class node select the DiscordRpc class.

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

Create a Cast node to your Game Instance.

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

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

Here’s the final result using the settings above:

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.