/Dissonity

Open source project that makes it easy to interact with the Discord Embedded App SDK using Unity

Primary LanguageC#MIT LicenseMIT



Dissonity allows you to build Discord activities using Unity.

Previously named Unity-Embedded-App-SDK. This project has been developed for Unity 2022 or later but it should work with all the LTS versions.

Dissonity is designed for a structure similar to the nested-messages example from Discord. You may want to familiarize with that project structure first.

Example Unity script

using UnityEngine;
using static Dissonity.Api;

public class MyScript : MonoBehaviour
{
    async void Start()
    {
        string userId = await GetUserId();
        Debug.Log($"The user's id is {userId}");

        SubActivityInstanceParticipantsUpdate((data) => {
            Debug.Log("Received a participants update!");
        });
    }
}

Note

You can implement these packages yourself, or start with the Node.js example project inside the examples folder.

Design

This project consists of two main packages:

  • Dissonity NPM
  • Dissonity Unity

To use Dissonity you need a Node.js project that uses the Dissonity NPM package and a Unity project that uses the Unity package.

In the Unity project you will have access to methods that allow you to interact with the Embedded App SDK. Behind the scenes, the SDK is still in the Node.js part. Both packages share data to provide functionality.

When running the activity, your game build will be inside a nested iframe inside the Node.js client that we will call "child" (more on this later).

Installation

First of all, you need to have installed:

  • Node.js
  • Unity 2022 or later
  • Git (recommended)

Node.js

  1. Install the npm package with npm install dissonity
  2. Inside the client's index.js, call setupSdk with your config (sample)
  3. Make sure the iframe where your build will be has the id dissonity-child (sample)
  4. Configure your server to send the proper content headers (sample)

That's everything you need in the Node.js client.

Notice you don't need to manually create a DiscordSDK instance.

Unity

  1. Go to Window > Package Manager > Add package from git URL
  2. Install the package from https://github.com/Furnyr/Dissonity.git?path=/unity
  3. Right click in the hierarchy, Dissonity > Discord Bridge
  4. You can now build your game for WebGL and put it in your nested iframe. If you're not using the example Node.js project you will need to follow the "Project configuration" guide below.

If you don't know how to test your activity refer to the Discord documentation.

Important

If you don't add the Discord Bridge object to your scene you won't be able to receive data from the SDK!

Links

Examples

There are code samples and an example Node.js project (using Colyseus for multiplayer support!) inside the examples folder.

If you find a bug, don't hesitate to open an issue. Now go and build something cool! :)