No video

How to implement Discord Rich Presence into your Unity game and update it in Real Time

  Рет қаралды 15,174

Sven Tomasek

Sven Tomasek

Күн бұрын

Discord SDK - / discord
Discord App - / discord
My Script - github.com/sve...
/* Music used in the video */
‪@KUBBIkthxbai‬ - Polar Bear Rides
‪@KUBBIkthxbai‬ - Something New

Пікірлер: 96
@sventomasek
@sventomasek 2 жыл бұрын
Note: I didn't know this at the time of making the video, but Discord slows down the activity update frequency the more it needs to update it, so having a number that constantly changes will not be displayed correctly, it will update it every 5-20 seconds. This still works correctly as long as you don't need to update it constantly. It is an issue on Discord's end so nothing I could do. If you want to see how I used this method in my game sventomasek.itch.io/umami-island Discord_Controller.cs - github.com/sventomasek/Discord-Script-for-Unity/blob/main/Discord_Controller.cs
@itsjust246
@itsjust246 Жыл бұрын
how to add buttons
@jakeinalake_
@jakeinalake_ Жыл бұрын
This video had text explaining what to do, background music and was very understanding to follow! Thanks for making an actual understandable tutorial!
@joshuamaitland
@joshuamaitland Жыл бұрын
Very good! I will use it for my future unity projects!! Thanks for this tutorial.
@Dilithium1
@Dilithium1 Жыл бұрын
THANK YOU FOR THIS VIDEO SO MUCH!!
@realzoogies
@realzoogies 8 ай бұрын
+1, to the point with link to source script provided
@angelicaz1332
@angelicaz1332 11 ай бұрын
such detailed steps! you are awesome!
@aihkww
@aihkww 5 ай бұрын
W video
@korbyntalks
@korbyntalks Жыл бұрын
omg tysmmm you need more recognition, Subbed!
@korbyntalks
@korbyntalks Жыл бұрын
oh and also do you have a solution for uhm this? So I really want it to show what scene your on in the status thing, Got anything?
@sventomasek
@sventomasek Жыл бұрын
@@korbyntalks To get the name of the Scene you can use SceneManager.GetActiveScene().name which you can write in State or Details (where rb.velocity is in my script)
@slicetheduck
@slicetheduck Жыл бұрын
This really helped me implement DiscordRpc into a game using BepInEx i did have to change some things but still thank you!
@sventomasek
@sventomasek Жыл бұрын
I'm glad I could help!
@HighPalace123
@HighPalace123 Жыл бұрын
Thank you!
@malyplus9839
@malyplus9839 Жыл бұрын
hey! Thanks For Tutorial!
@laym.glitched
@laym.glitched 11 ай бұрын
AMAZING TUTORIAL!!! Loved it! and also i Liked and Subbed! but 1 quick question: In your Awake() for my else if, its telling me FindObjectsOfType() is deprecated, and makes it so I have to restart discord to remove the discord rpc, any way to fix this?
@sventomasek
@sventomasek 11 ай бұрын
Thank you! Are you getting an error or a warning? If it's a warning I think the function should still work fine, it just may have a different name in the future Unity versions. But if you're not sure you can reply with the full error message here. As for having to restart Discord that's probably because you're in the Unity editor. Try building the game and check if it works fine that way.
@laym.glitched
@laym.glitched 11 ай бұрын
@@sventomasek Thanks for the quick reply! Its just a vs warning and here is the full error for more info: Warning CS0618 'Object.FindObjectsOfType(Type)' is obsolete: 'Object.FindObjectsOfType has been deprecated. Use Object.FindObjectsByType instead which lets you decide whether you need the results sorted or not. FindObjectsOfType sorts the results by InstanceID, but if you do not need this using FindObjectSortMode.None is considerably faster.' Ill will try to build it and see if it fixes, Thank you so much!
@kirdow
@kirdow 4 ай бұрын
How do I add buttons? I recall seeing some rich presences users have contain buttons below the details that you can click. Looking at the discord documentation Buttons should exist as an array of objects taking Label and Url, but there seem to be no Buttons property under the Activity class. Am I missing something important for that to work?
@YURIKZbutSJ
@YURIKZbutSJ Жыл бұрын
THANK YOU SO MUCH!!!!
@RadSow
@RadSow Жыл бұрын
Wonderful tutorial! Will it work if I send it to someone else? Do they also have to have the application created at their account or not?
@sventomasek
@sventomasek Жыл бұрын
Yes it will work for everyone using Discord. The only person that needs to create the application is the developer.
@RadSow
@RadSow Жыл бұрын
@@sventomasek THX FOR THE FAST REPLY! You are wonderfull
@RadSow
@RadSow Жыл бұрын
@@sventomasek I'll drop a sub for you and I hope you will make more useful tutorials like this one :D
@sventomasek
@sventomasek Жыл бұрын
@@RadSow Thank you!
@RadSow
@RadSow Жыл бұрын
@@sventomasek You're Welcome. Also, I just downloaded your game, and after I try it I'll definitely put a review (probably 5/5 stars but we'll see :D)
@exator911
@exator911 7 ай бұрын
I'm having an issue with the timestamp for how the game has been running. The code is there and it should work however it doesn't appear properly. The time shows a zero or nothing at all.
@krippanus
@krippanus Жыл бұрын
problem: when you close the game build or exit playtesting mode, the rich presence from that session stays and will not update when starting again.
@sventomasek
@sventomasek Жыл бұрын
That's because the Rich Presence only disappears after you close the application which means you would need to close Unity itself. When you export the game and run it outside Unity that won't be a problem.
@krippanus
@krippanus Жыл бұрын
@@sventomasek just checked. when it's exported, it doesn't work at all.
@krippanus
@krippanus Жыл бұрын
wait fuck... i had the architecture wrong
@krippanus
@krippanus Жыл бұрын
the problem was entirely on me, my bad
@sventomasek
@sventomasek Жыл бұрын
@@krippanus Well I'm glad you figured it out ^^
@4Raynixx
@4Raynixx 2 ай бұрын
How to add Buttons?
@blob7115
@blob7115 Жыл бұрын
thanks
@krippanus
@krippanus Жыл бұрын
"Multiple plugins with the same name 'discord_game_sdk' (found at 'Assets/Plugins/lib/x86_64/discord_game_sdk.dll' and 'Assets/Plugins/lib/x86/discord_game_sdk.dll'). That means one or more plugins are set to be compatible with Editor. Only one plugin at the time can be used by Editor." bruh
@Davis_Bogdanovs
@Davis_Bogdanovs Жыл бұрын
To fix this error I opened the Plugins folder and then the x86 folder, in there for the discord_game_sdk file I checked to exclude Editor. Might want to do the same for Android/iOS if you are exporting your project to mobile devices as otherwise it might give you errors
@krippanus
@krippanus Жыл бұрын
@@Davis_Bogdanovs you're... a little late, don't you think? i fixed it months ago already. not sure what i did.
@juzdepeche
@juzdepeche Жыл бұрын
@@Davis_Bogdanovs You're not late for me, thanks!
@Sk8_
@Sk8_ 2 жыл бұрын
Great video, I've just started development on a retro fps game so this has really helped me out. I do have a question, which is: How do I go about changing the status when a user loads a new scene, I cant re-implement the discord controller from scene to scene and change the value of the 'details' and 'state' because the first one is already running. So how can this be achieved?
@sventomasek
@sventomasek 2 жыл бұрын
Thanks! How I would go about this is making another script that finds the DiscordController and changes the variables in the Start function. Here's an example, you can just copy and paste it if you want. Let me know if you have any issues with it! using UnityEngine; public class Discord_Changer : MonoBehaviour { public string newDetails = "Example Details"; public string newState = "Example State"; [Space] public string newLargeImage = "game_logo"; public string newLargeText = "Example Text"; void Start() { Discord_Controller discord = GameObject.Find("DiscordController").GetComponent(); discord.details = newDetails; discord.state = newState; discord.largeImage = newLargeImage; discord.largeText = newLargeText; } }
@Sk8_
@Sk8_ Жыл бұрын
@@sventomasek Sorry for the late reply, thank you for this. I'll be sure to test it out.
@jozatheman
@jozatheman Жыл бұрын
@@sventomasek do i have to create a seperate gameobject for this?
@sventomasek
@sventomasek Жыл бұрын
@@jozatheman Yes, you place that script onto a new game object in each scene you want to change the status in.
@joshuamaitland
@joshuamaitland Жыл бұрын
Well... Even if Discord is not running, I'm getting this error: ResultException: InternalError Discord.Discord..ctor (System.Int64 clientId, System.UInt64 flags) (at Assets/Plugins/DiscordGameSDK/Core.cs:1075) DiscordManager.Start () (at Assets/Scripts/Managers/DiscordManager.cs:37) Any ideas?
@MCew_prv
@MCew_prv Жыл бұрын
I now have a different problem, when i started the game and launch spotify, then the spotify rich presence gets on top of the one from my game. If I would to the same with any other game then the spotify rich presence would stay behind the one of the game and would only be viewably if i close the game.
@sventomasek
@sventomasek Жыл бұрын
That's probably because those games have an official rich presence provided by Discord, so I don't think anything can be done about that unless Discord adds a status priority option or the user disables their Spotify rich presence in Discord settings.
@Delta-Warrior
@Delta-Warrior 8 ай бұрын
when i close the game it keeps the status how would i fix that?
@sventomasek
@sventomasek 8 ай бұрын
That should only happen in the Unity editor. Try exporting the game and see if it still happens.
@kiatu2352
@kiatu2352 9 ай бұрын
whenever i start up a new session it creates a new activity on my discord profile, is there a way to make sure only one of itself is present in my activities tab?
@sventomasek
@sventomasek 9 ай бұрын
That's because you're in the Unity editor so activities close only when you close Unity. When you export the game it should work fine.
@LukeKido
@LukeKido Жыл бұрын
Made a small 2D doodle and it worked like a charm! How can I set the logo to be shown on Discord?
@sventomasek
@sventomasek Жыл бұрын
You have to upload your logo on the Discord Applications website like shown at 0:52 (name it whatever you want), then make a string "largeImage" and set it to whatever you named your logo on the website, like shown at 2:49. Then like at 6:30 under Assets you add LargeImage = largeImage and it should be working. If it's not try waiting a few minutes since it takes Discord some time to approve the image you upload.
@LukeKido
@LukeKido Жыл бұрын
Thanks a lot for your quick reply and explaining every step 🥰
@Il_Tizio
@Il_Tizio Жыл бұрын
Unity say that this script can't be loaded and I need to fix it, but the console didn't expose any error
@sventomasek
@sventomasek Жыл бұрын
Can you post a screenshot of the error you're getting? You can upload it to imgur for example and post a link here.
@MCew_prv
@MCew_prv Жыл бұрын
Getting this error: "NullReferenceException: Object reference not set to an instance of an object Discord_Controller.Start () (at Assets/Scripts/Discord_Controller.cs:39)" Can someone help me?
@sventomasek
@sventomasek Жыл бұрын
You probably forgot to add a Rigidbody to your player object like at 8:51 or forgot to add the tag "Player" like at 8:45 If that doesn't work double check if you misspelled something, the line should be "rb = GameObject.FindWithTag("Player").GetComponent();" unless you changed some code. Let me know if you need more help!
@MCew_prv
@MCew_prv Жыл бұрын
@@sventomasek thanks a lot, i didnt implemented the rigidbody because i habe a 2d Game and have no Moving player so i can try to simply remove it. I didnt thought of still having code with the rigidbody. Thanks
@LeftoverAtoms
@LeftoverAtoms Жыл бұрын
Copied the script and tutorial 1-1 and I have no rich presence?
@sventomasek
@sventomasek Жыл бұрын
Do you have activity status turned on in Discord? It's under settings > activity privacy > display current activity as a status message
@RubyPiec
@RubyPiec Жыл бұрын
what if i wanna do this for a game that isnt mine?
@sventomasek
@sventomasek Жыл бұрын
Then you would have to learn how to mod the game, which I wouldn't know how to do.
@RubyPiec
@RubyPiec Жыл бұрын
@@sventomasek ah, okay. there arent any tutorials for this unfortunately either :( this was like the best i could find
@pietro420
@pietro420 Жыл бұрын
Bro, for some reason it says "Internal Error" on the console
@sventomasek
@sventomasek Жыл бұрын
I can't help you without the full error.
@pietro420
@pietro420 Жыл бұрын
@@sventomasek I got it now, it was because my discord rpc server was turned off
@AenR1
@AenR1 Жыл бұрын
can u help how can we show scene name in rpc like playing in {worldname} world
@sventomasek
@sventomasek Жыл бұрын
You can get the scene name using SceneManager.GetActiveScene().name Don't forget to reference UnityEngine.SceneManagement at the start of the script.
@AenR1
@AenR1 Жыл бұрын
@@sventomasek thx i did and can we add buttons?
@sventomasek
@sventomasek Жыл бұрын
@@AenR1 Haven't really looked into it, but you can search for it in the documentation discord.com/developers/docs/intro I might make a video on how to do it in the future.
@AenR1
@AenR1 Жыл бұрын
@@sventomasek thx a lot
@ekal3_YT
@ekal3_YT 6 ай бұрын
what does the noclip thing do, does it work?
@sventomasek
@sventomasek 6 ай бұрын
I don't really know what you're referring to. Can you be more specific and maybe write a timestamp?
@ekal3_YT
@ekal3_YT 6 ай бұрын
8:00 it says in movement no clip
@sventomasek
@sventomasek 6 ай бұрын
@@ekal3_YT It allows me to fly and move through walls when enabled for debugging purposes. I haven't included it in this video as the video is about discord rich presence and not player movement.
@ekal3_YT
@ekal3_YT 6 ай бұрын
oh cool, thanks for the info
@eyepatch6726
@eyepatch6726 Жыл бұрын
How can we create rich presence for an already released famous games?I saw some people do it idk how though.
@sventomasek
@sventomasek Жыл бұрын
That would depend on the game. Try looking up if the game has some modding tools.
@eyepatch6726
@eyepatch6726 Жыл бұрын
@@sventomasek can't we do it without mod?because I want it to work with that game in real time
@--__--__--__--__--__--__--__--
@--__--__--__--__--__--__--__-- Жыл бұрын
my image is not working
@sventomasek
@sventomasek Жыл бұрын
You need to wait a few minutes for it to upload. If it still isn't working then double check if the image name on the website and name in the script is the same.
@--__--__--__--__--__--__--__--
@--__--__--__--__--__--__--__-- Жыл бұрын
@@sventomasek now it works but i have another question, can i add like buttons that for example send me to project page when i click them?
@thelelik0
@thelelik0 2 жыл бұрын
Help me please Assets/Script/Discord_Controller.cs(42,42): error CS1061: Type `System.DateTimeOffset' does not contain a definition for `ToUnixTimeMilliseconds' and no extension method `ToUnixTimeMilliseconds' of type `System.DateTimeOffset' could be found. Are you missing an assembly reference?
@sventomasek
@sventomasek 2 жыл бұрын
Can you post your code here? It's a bit hard to figure out what's wrong without it.
@thelelik0
@thelelik0 Жыл бұрын
@@sventomasek Yes, using System.Collections; using System.Collections.Generic; using Discord; using UnityEngine; public class Discord_Controller : MonoBehaviour { public long applicationID; [Space] public string details = "Исследует мир!"; public string state = "Текущие координаты: "; [Space] public string largeImage = "1"; public string largeText = "Project Porcelain"; private Rigidbody rb; private long time; private static bool instanceExists; public Discord.Discord discord; void Awake() { // Transition the GameObject between scenes, destroy any duplicates if (!instanceExists) { instanceExists = true; DontDestroyOnLoad(gameObject); } else if (FindObjectsOfType(GetType()).Length > 1) { Destroy(gameObject); } } void Start() { // Log in with the Application ID discord = new Discord.Discord(applicationID, (System.UInt64)Discord.CreateFlags.NoRequireDiscord); rb = GameObject.FindWithTag("Player").GetComponent(); time = System.DateTimeOffset.Now.ToUnixTimeMilliseconds(); UpdateStatus(); } void Update() { // Destroy the GameObject if Discord isn't running try { discord.RunCallbacks(); } catch { Destroy(gameObject); } } void LateUpdate() { UpdateStatus(); } void UpdateStatus() { // Update Status every frame try { var activityManager = discord.GetActivityManager(); var activity = new Discord.Activity { Details = details, State = state + rb.velocity, Assets = { LargeImage = largeImage, LargeText = largeText }, Timestamps = { Start = time } }; activityManager.UpdateActivity(activity, (res) => { if (res != Discord.Result.Ok) Debug.LogWarning("Failed connecting to Discord!"); }); } catch { // If updating the status fails, Destroy the GameObject Destroy(gameObject); } } }
@sventomasek
@sventomasek Жыл бұрын
@@thelelik0 The same code works fine for me. Do you have .NET Framework installed?
@slicetheduck
@slicetheduck Жыл бұрын
If you are using dontet 4.5 or ealier try "(int)System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1)).TotalSeconds;" The method used in the video only works for 4.6 and up, althogh unless you have stuff that specifically requires dotnet 4.5 or lower id recommend bumping up those versions.
@raingayming
@raingayming Жыл бұрын
i get the error ```ResultException: InternalError Discord.Discord..ctor (System.Int64 clientId, System.UInt64 flags) (at Assets/Plugins/DiscordGameSDK/Core.cs:1017)``` can anyone help?
@sventomasek
@sventomasek Жыл бұрын
Sorry for the late reply. Have you tried making a new Unity project and following the steps again? I don't know how to replicate the error so that's my best guess. Also make sure to place all the files into correct paths like I did in the video.
How to ACTUALLY get into Gamedev
14:01
DaFluffyPotato
Рет қаралды 718 М.
Before VS during the CONCERT 🔥 "Aliby" | Andra Gogan
00:13
Andra Gogan
Рет қаралды 10 МЛН
Magic trick 🪄😁
00:13
Andrey Grechka
Рет қаралды 55 МЛН
艾莎撒娇得到王子的原谅#艾莎
00:24
在逃的公主
Рет қаралды 54 МЛН
I made a Battle Royale Game in my Discord Server
12:56
Jelle Vermandere
Рет қаралды 205 М.
How I Became a Sea of Thieves Developer
8:05
Zyger
Рет қаралды 224 М.
How to get an ANIMATED Discord Rich Presence!
7:14
No Text To Speech
Рет қаралды 822 М.
I tried Discord Bot Makers...
14:19
FaceDev
Рет қаралды 120 М.
Create Immersive Discord Activities with Unity and SvelteKit
9:59
The Sleepy Koala
Рет қаралды 3,3 М.
I watched 121 FPS guides and they’re full of lies
20:07
Aaron Bong
Рет қаралды 1,1 МЛН
I Wish I Had Known This Before I Started Unity Game Development...
11:11
Making a game where you get sucked into your own (bad) code
23:10
Robert Thomson
Рет қаралды 1,3 МЛН
HACKING UNITY GAMES (FOR NOOBS)
16:11
cazz
Рет қаралды 81 М.