Unity Initialization

Code Free

  • Set your desired settings.

  • Add a component to the game object

  • Done!

With Configuration

  • Doesn't require a GameObject

  • Single line of code

Pure Code

  • Doesn't require a GameObject

  • No ScriptableObject

  • Pure C#

Pure Code

You do NOT require any GameObjects to make Discord Social run. You can simply call our DiscordSocialApp API, and we will handle initialisation of the required objects and optionally start the connection process as soon as ready.

Namespace

using Heathen.DiscordSocialIntegration.API

Initialize

You should ask your user before you attempt to connect.

A simple way to do this is a "Connect to Discord" button on your main menu or in your settings. When clicked, it should store that the user does want to connect to Discord, and you can use that value in the future to auto-connect.

DiscordSocialApp.Initialize(123456789987654, true);

Provide your "Client ID", also sometimes called an "Application ID"

The second parameter (auto connect) indicates whether or not the system should attempt to connect once initialised. You can set this to false and request a connection on demand later.

Connect

If you choose to differ connection (passed false into the Initialise function), you will need to call Connect when ready.

The first time the app connects to a user's Discord will take focus and ask the user to "Authorise" the app.

DiscordSocialApp.Connect();

Events

The Discord Social SDK initialisation and connection process passes through a number of steps in the background. Each step is represented by a Unity Event you can listen to if desired. All events are part of the DiscordSocialApp static class, the same class you used to call Initialise and Connect.

The only event that matters is OnReady, which is triggered when the entire system is ready to be used.

OnAuthorizeResult

public static UnityEvent<ClientResult, string, string> OnAuthorizeResult

Triggers when OAuth authorisation provides the required callbacks.

OnConnect

public static UnityEvent OnConnect

Triggers when the system completes the connection.

OnDisconnect

public static UnityEvent OnDisconnect

Triggers when the system disconnects from Discord.

OnReady

public static UnityEvent OnReady

Triggered when the system state updates to Ready and is thus ready to be used.

OnReceivedToken

public static UnityEvent OnReceivedToken

Triggard, when token retrieval completes

OnRetrieveTokenFailed

public static UnityEvent OnRetrieveTokenFailed 

Triggered when the token request responds with a state of failed.

OnStatusChanged

public static UnityEvent<Client.Status, Client.Error, int> OnStatusChanged

Triggers with every system state change, connecting, connected, ready, disconnecting, disconnected, etc.

Object

When you configured your Discord Social Settings, it created DiscordSocialSettings Objects that can be used to initialise directly. The initialisation function on these objects will read all required data from them.

Configuration Guide

Component

If you need a code-free solution, we provide you with a component script, Initialise Discord Socialwhich will initialise the Steamworks SDK for you based on your configured Steam Settings.

You DO NOT need to mark this component as Do Not Destroy on Load ... it does not need to persist between levels and only exists to call Initialise for you.

Last updated