Set up Discord Rich Presence in Unity

Set up Discord Rich Presence in Unity thumbnail
Set up Discord Rich Presence in Unity thumbnail
Discord offers a neat feature called Rich presence, which lets you see not only what games your friends are playing, but also gives extra details like:
  • The current game state
  • How long someone has been playing
  • The ability to join or spectate a game directly
I’m gonna show you how to set up and customise Discord Rich Presence for your Unity Games

Setup Your Unity Game

First we need to quickly setup our game:
  1. Head over to discord.com/developers and log in using your Discord account
  2. Create a new Application and give it the same name as your game.
  3. Once your application is created, go to the Rich Presence tab on the left, and click on Visualiser to preview how your rich presence will look on Discord.
    Discord Rich Presence Visualizer
    Preview

Add Discord SDK to your Unity game

Now, let’s integrate the Discord SDK into your Unity game code
  1. Download the Discord SDK package from this link: https://github.com/HouraiTeahouse/Discord-Game-SDK
  2. Open Unity, go to WindowPackage ManagerAdvanced Project Settings.
  3. Add scoped registries: Enter following details and click Apply
    Unity advanced project settings
    Preview
  4. Open Unity Package Manager, select Add package byt name, and paste this: com.discord.game-sdk

Create Discord manager script

Now, let’s add a new script, which will initialize Discord SDK and enable our Rich Presence message.
  1. Create a new script in Unity and call it DiscordManager.
  2. Paste in this code:
C#
1using System.Collections;
2using System.colections.Generic;
3using UnityEngine;
4
5public class DiscordManager : MonoBehaviour
6{
7	Discord.Discord discord;
8	
9	// start is called before the first frame update
10	void Start()
11	{
12		discord = new Discord.Discord(1179743438971883550, (ulong)Discord.CreateFlags.NoRequireDiscord);
13		ChangeActivity();
14	}
15	
16	void OnDisable() {
17		discord.Dispose();
18	}
19	
20	public void ChangeActivity() {
21		var activityManager = discord.GetActivityManager();
22		var activity = new Discord.Activity {
23			State = "Playing",
24			Details = "Hello world!"
25		};
26		activityManager.UpdateActivity(activity, (res) => {
27		
28		});
29	}
30	
31	// Update is called once per frame
32	void Update()
33	{
34		discord.RunCallbacks();
35	}
36{
Enter the APPLICATION ID that can be found in the Discord developer portal (General information tab)

Run Your Unity Game

Now, when you run your Unity game, Discord will display a Rich Presence widget with all details you set up.
Discord Rich Presence demo
Preview

Rich Presence Customisation

As I mentioned earlier, Discord provides a visualiser in developer dashboard that lets you preview and test your Rich Presence settings:
  1. Go to Discord developer dashboard and open the Visualiser
  2. Fill out the fields with desired text for status and state
  3. Go to Art assets and Upload Graphics
  4. Select images in Visualiser
  5. Use template below to add the data to your code:
    C#
    1State = "Playing single mode",
    2Details = "Exploring the world",
    3Assets = {
    4	LargeImage = "map_1"
    5	LargeText = "Green hills"
    6	SmallImaga = "class_warrior"
    7	Smalltext = "Warrior (Lvl 32)"
    8},
    9Timestamps = {
    10	Start = 1701344113
    11},
    12Party = {
    13	Id = "room123",
    14	size = {
    15		Curentsize = 2,
    16		Maxsize = 5,
    17		}
    18}
You can use those settings in the DiscordManager (we’ve created earlier) to customise the Rich Presence!

Bonus Tip!

You don’t need to rely on Discord predefined assets. You can use custom images by providing images URLs
Just remember to use copyright free images or ones that belong to you!
And that’s it! You’ve got a functional and customizable Discord Rich Presence for your Unity game. Have fun and show off your game's activity to your friends on Discord!
divider
discord
Hi! Why don’t you visit my discord?
Copyright © 2024 Teal Fire