Skip to content

About

A Unity sample project demonstrating integration with the Discord Social SDK designed with best practices in mind.

Topics

Resources

Contributing

Stars

28 stars

Watchers

2 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

Discord Social SDK Unity Sample

A Unity sample project demonstrating integration with the Discord Social SDK designed with best practices in mind.

Preview.mov

What This Sample Includes

This sample showcases many Discord Social SDK features in a complete, interactive Unity scene:

  • Account Linking & Authentication: Discord OAuth2 integration with secure token storage
  • Friends List: Display and interact with Discord friends lists
  • Rich Presence: Dynamic Discord activity cards with lobby and invite integration
  • Game Lobbies: Create, join, and manage multiplayer lobbies
  • Game Invitations: Send invites for friends to join your lobby

Planned features that haven't been implemented yet:

  • Direct Messaging: In-game messaging
  • Linked Channels: Connect game chat to Discord server channels
  • User Profiles: Fetch and display Discord user information

Questions This Sample Answers

How do I connect my players to each other and bring new players to my game?

By creating an in-game friends list you can help players connect with each other while playing. Using the Discord Social SDK to do this allows you to leverage a player's existing Discord friends as well as make new friends in game. Creating a friends list for your game is the main social building block that allows you to add messaging and invites which keep players in your game and help bring in new players through their friends.

How do I create friends list for my game and keep it updated and sorted?

Using the Discord Social SDK you can fetch a player's friends list and display it in your game. This sample demonstrates how to fetch the friends list, display each friend's username, status, and avatar, and keep it updated in real-time. It also shows how to sort friends by their online status and username.

How do I handle performance with a friends list in my game?

By sorting friends client-side and only updating the UI when there are changes, you can create a responsive friends list. This sample keeps the friends list updated in real-time by only updating the UI for an individual player when their info changes and then sorts them into the proper position in the UI. It doesn't create or destroy any UI elements once they've been initialized.

How can I make my game more discoverable? How can I help my game go viral?

Using Rich Presence makes it easy for friends to see what you're playing and join in directly from Discord. Allowing invites through your game's UI lets players invite their friends through the game or Discord. With Discord being the social platform for gamers, integrating the Discord Social SDK makes it easy for players to connect and play together, increasing your game's visibility and player base.

Quick Start

Prerequisites

  • Unity 6 or later
  • Discord Developer Account

Setup Instructions

  1. Clone the Repository

    git clone https://github.com/discord/social-sdk-unity-sample.git

    or download the ZIP file from the GitHub repository.

  2. Open in Unity

    • Launch Unity Hub
    • Click "Add" and select "DiscordSocialSDKUnitySample" from the cloned repository or extracted ZIP
    • Open the project
  3. Configure Your Discord Application

    • Visit the Discord Developer Portal
    • Create a new application or use an existing one
    • Navigate to the Discord Social SDK > Getting Started section
    • Fill out the form
    • Click Submit and the Social SDK will be enabled for your application
    • Navigate to the OAuth2 tab:
      • Under "Client information" enable Public Client
      • Under "Redirects" add a redirect URL http://127.0.0.1/callback
    • Navigate to Discord Social SDK > Downloads
    • Download the latest SDK (DiscordSocialSdk-UnityPlugin-X.X.X.zip)
    • Either:
      • Unzip the zip file in the Unity Packages folder, or
      • Unzip the zip file and Install Package from Disk. Make sure the folder is in a directory that won't get moved or deleted as your Unity project will load it from that location.
Screenshot 2025-07-24 at 9 01 00 AM
  1. Configure the Sample

    • In Unity open the Example scene
    • In your asset folder right click > Create > Config > Discord Social SDK
    • Click on the Social SDK Config and paste your Application ID found under "General Information" from the application you created in the Discord Developer Portal
    • Drag your Discord Social SDK Config into the DiscordManager object in the scene
  2. Run

    • Press the play button to test it in the Editor
    • Click on the "Connect to Discord" button in the UI
    • Discord or the browser should open to authorize the application
    • After authorizing, you should see your Discord friends list show up in the sample and your Rich Presence should update to show you are playing the sample game
    • You will also see all logging in the Unity Console
Screenshot 2025-07-24 at 9 04 36 AM

Troubleshooting

The type or namespace name 'Discord', 'Client', etc... could not be found (are you missing a using directive or an assembly reference?)

If you see errors related to missing types or namespaces, it likely means that the Discord Social SDK is not installed correctly. Make sure you followed all the setup instructions and that the SDK is properly imported into your Unity project.

Mac libdiscord_partner_sdk.dylib Not Opened

On Mac you may get the error "libdiscord_partner_sdk.dylib" Not Opened because Apple couldn't verify it. If this happens press Done on the popup. You'll need to open your System Settings > Privacy & Security and scroll down to the Security section. It will tell you "libdiscord_partner_sdk.dylib" was blocked to protect your Mac. Press Open Anyway and try running again. Now when you get the pop up you'll have the option to select Open Anyway and it will be able to use it successfully.

Nothing happens when I click the "Connect to Discord" button

If nothing happens when you click the "Connect to Discord" button, make sure you have a DiscordManager in your scene and that it has a valid DiscordSocialSdkConfig assigned. You can find the DiscordManager prefab already set up for you in the Prefabs folder. Also check the Unity Console for any errors.

Opening Project in Non-Matching Editor Installation

You'll see this warning if you open the project in a different version of Unity than it was created with. It's safe to ignore as long as you're opening the sample in a compatible version (Unity 6+). You can press "Continue" and you might get another modal saying "URP Material upgrade" which you can safely press "Ok" on.

Mobile Setup

This sample runs on Android and iOS as well as desktop. For mobile, open and build Assets/Scenes/Mobile.unity, a portrait, mobile-first scene. It uses its own touch-friendly UI prefabs in Assets/Prefabs/Mobile/ but shares the same DiscordManager and SDK logic as the desktop Example scene.

Add the mobile redirect URI

Mobile OAuth redirects through a custom URL scheme instead of the desktop loopback address, and Discord rejects any redirect that isn't registered. In the Discord Developer Portal, open your app's OAuth2 settings and add this under Redirects:

discord-<APP_ID>:/authorize/callback

Replace <APP_ID> with your Application ID, for example discord-1234567890:/authorize/callback. Keep your desktop http://127.0.0.1/callback redirect from the Quick Start too; the SDK uses the right redirect for each platform automatically. Without the mobile entry, login fails because Discord won't redirect to an unregistered URI.

The redirect scheme is registered on-device for you

For that redirect to reach the app, the discord-<APP_ID> scheme also has to be declared in each platform's build output, which normally means hand-editing the Android manifest and iOS Info.plist. Two editor scripts in Assets/Scripts/Editor/ do this for you at build time, reading your Application ID from DiscordSocialSdkConfig:

  • AndroidPostBuildProcessor.cs adds the com.discord.socialsdk.AuthenticationActivity entry and its discord-<APP_ID> intent filter to the Android manifest.
  • iOSPostBuildProcessor.cs adds the discord-<APP_ID> scheme to CFBundleURLTypes (so the redirect returns to your app) and discord to LSApplicationQueriesSchemes (so login can deep link into the Discord app) in the iOS Info.plist.

Set your Application ID once and build; the scripts register the redirect scheme for you.

Game invites on mobile

RichPresence.cs sets activity.SetSupportedPlatforms(Desktop | IOS | Android), so friends can accept your game invites from a mobile device. Accepting an invite while the game is already running joins the lobby with no extra setup.

Launching the game from an invite when it is closed is not set up in this sample. Discord launches a closed game through a deep link URL configured on your app's General tab in the Developer Portal, which requires an https link (an iOS Universal Link / Android App Link) backed by a domain you control. That part is specific to your app and domain, so it lives outside this sample.

Mobile Troubleshooting

Login opens Discord or the browser, but never returns to the app

The mobile redirect URI isn't registered. Add discord-<APP_ID>:/authorize/callback to your app's OAuth2 > Redirects in the Developer Portal, exactly as shown above. This is separate from the on-device scheme the build scripts register.

Mobile.mov

Project Structure

This sample creates easy to use prefabs that can be used to build out parts of the Discord Social SDK. The central piece is the DiscordManager which handles the connection to Discord and provides access to the SDK features. In order to use the DiscordManager, you need to create a DiscordSocialSdkConfig Scriptable Object with the Application ID from the Discord Developer Portal and assign it to the DiscordManager. The friend list is built using the FriendsList prefab, which contains the logic to fetch and display friends. Each friend is represented by a FriendUI prefab that shows their username, status, and profile picture. Rich Presence is handled by the RichPresence prefab, which updates the user's activity status in Discord. The Lobby prefab allows the player to create and leave a lobby which will update their Rich Presence and allow their friends to request to join their lobby through the Discord client. Each prefab is easy to drop into your scene and customize as needed.

For mobile, the Mobile scene uses touch-friendly variants of these prefabs in Assets/Prefabs/Mobile/ (such as MobileUI, MobileFriendsList, and FriendUIMobile). They share the same DiscordManager and SDK logic as the desktop prefabs, so only the presentation differs.

Resources

Documentation

Design Resources

Videos

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is licensed under the Discord Social SDK Terms. See the LICENSE file for details.


Built with ❤️ by the Discord Developer Relations team

Questions? Check out the #social-sdk-dev-help channel in the Discord Developers server!

About

A Unity sample project demonstrating integration with the Discord Social SDK designed with best practices in mind.

Topics

Resources

Contributing

Stars

28 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages