Demo Game (Template)

// Config: Engine - [], Toolkit - [v1.0.0]

Demo Game (Template) is a sample in Toolkit for Discord Social. It is a small game flow that shows how to gather players with Discord friends and lobbies, tell everyone when a session is ready, and hand over to your own networking library for the actual connection. It is one scene: sign in, friends, requests, lobby, invite and session. There is no Steam in it.

Start here #

  1. Set your Discord Application Id in Project Settings, Subsystems, Discord Social. The demo shows a “Setup needed” box until you do.
  2. Import the sample from the Package Manager, open Scenes/Discord Demo (Template).unity and press Play.
  3. Press Sign in, approve the request in Discord, and your profile, friends and requests appear. The demo remembers you, so the next Play signs in on its own. Sign out forgets the saved sign in.
  4. Create lobby, then Invite a friend, or send them the lobby code to paste into Join. They get an in-game prompt.
  5. The host presses Start session. Every member enters the session and gets a capsule. Move with WASD and Space.

You need two Discord accounts on two machines to try the whole flow. The sign in, friend list and invites are Discord’s; nothing in the demo is simulated.

What Discord does and what it does not #

Discord provides identity, friends, presence, the lobby, invites and voice. It carries no game traffic. When the host presses Start, the demo starts the host’s network, then sends the address clients should connect to as a lobby message. Each client receives it and connects. The connection itself is whatever your networking library does by default.

The demo ships with PlaceholderNetwork, which does not connect to anything, so each player runs the session alone. To make it a real game, write a DemoNetwork subclass for your library and put it in the scene in place of the placeholder. Every place to change is marked NETWORKING in the code. See Integrating networking.

Discord has no relay, so the host’s address must be reachable by the other players: the same network, a VPN, or a forwarded port.

Only lobby members may connect #

DemoWhitelist records who was in the lobby when the session started. Call DemoWhitelist.IsAllowed(discordUserId) in your server’s connection approval and refuse anyone who is not listed.

The rest of the demo documentation #

PageRead it when you want to know
Integrating networkingHow to plug in a networking library: the DemoNetwork contract, the whitelist and reachability.
ArchitectureHow the scene is organised and what happens, in order, from first launch to leaving a session.
ScriptsWhat every demo script and every Toolkit component the demo uses is for.
WiringWhich objects and components are in the scene and what references what.
TestingHow to test with one account and with two.
VoiceJoining the lobby’s voice call, 3D voice from a character, and the voice components.
TroubleshootingSymptoms, their causes and what to do.

Status #

The scene and scripts compile. Run against live Discord with one account, these work: sign in, signing in again on the next Play without the browser, your profile, the friends list with statuses, friend requests, changing your status, sending an invite, creating a lobby, starting a session (the session view with a capsule and the player’s name, the whitelist accepting the lobby member and refusing a stranger), leaving the session and the lobby, and voice (two-way voice between two accounts, joining, leaving and rejoining a call, and the voice setting toggles including noise cancellation).

Not yet confirmed: accepting an invite or joining by code on a second account, a session with several members, and hearing another person’s voice from their capsule through 3D voice. The networking is a placeholder until you add your own library.

Rate This Article!