The Godot Barn
Sign in
Sign in
Home
News & updates
Explore
Articles
Snippets
Shaders
Themes
Submit content
Sign in to submit content
Give or get help
Tutorials
Questions
Conversations
Coming soon!
GodotSteam Tutorial - Rich Presence
0
Description
"This short tutorial is all about rich presence for your game; specifically the game's enhanced rich presence. You have probably seen a friend in-game, in your friend list, that has a secondary text string with some information about the game. Usually something about the level they are on, a lobby, number of players, etc. Well, that's what this tutorial is all about.\r\n\r\n[You can read more about enhanced rich presence in the Steamworks documentation](https:\/\/partner.steamgames.com\/doc\/features\/enhancedrichpresence).\r\n\r\n??? guide Relevant GodotSteam classes and functions\r\n* [Friends class](https:\/\/godotsteam.com\/classes\/friends.md)\r\n * [setRichPresence()](https:\/\/godotsteam.com\/classes\/friends.md#setrichpresence)\r\n???\r\n\r\n!!! warning Note\r\nYou may want to [double-check our Initialization tutorial](https:\/\/godotsteam.com\/tutorials\/initializing) to set up initialization and callbacks functionality if you haven't done so already.\r\n!!!\r\n\r\n## Preparations{.block}\r\n\r\nFirst you will need to set up your localization file in the Steamworks back-end. Obviously without this step the rich presence text does not really work as it has nothing to reference. You will need to set up your text file like this and save it as **.vdf** file:\r\n\r\n```gdscript\r\n\"lang\" {\r\n\t\"Language\" \"english\"\r\n\t\"Tokens\" {\r\n\t\t\"#something1\" \"Rich presence string\"\r\n\t\t\"#something2\" \"Another string\"\r\n\t\t\"#something_with_input\"\t\"{#something%something_number%}: %score%\"\r\n\t}\r\n}\r\n```\r\n\r\nMake sure you tab separate the strings in the tokens bracket. Also make sure you publish the changes after your file is uploaded _before_ you try to test it. The changes must be live in Steamworks for it to appear.\r\n\r\nYou can put various languages in their own nests so these show up for users how have their Steam client language set specifically. The first string in each token is what you'll end up using in your game's code.\r\n\r\n## Suggested Code{.block}\r\n\r\nI have a global function, in my **steamworks.gd** that can be called anywhere in my project and handles this. It is written something like this:\r\n\r\n```gdscript\r\nfunc set_rich_presence(token: String) -> void:\r\n\t# Set the token\r\n\tvar setting_presence: bool = Steam.setRichPresence(\"steam_display\", token)\r\n\r\n\t# Debug it\r\n\tprint(\"Setting rich presence to %s: %s\" % [token, setting_presence])\r\n```\r\n\r\nAnd in whatever scene you want to set the token:\r\n\r\n```gdscript\r\nSteamworks.set_rich_presence(\"#something1\")\r\n```\r\n\r\nAnd now Steam will set the text in your friend's list to what you have set it as in the token list in the Steamworks back-end. You can also hover over your own profile picture to see the in-game text; for testing purposes.\r\n\r\nThere are additional tags you can set which are [covered in detail in the SDK documentation here.](https:\/\/partner.steamgames.com\/doc\/api\/ISteamFriends#SetRichPresence)\r\n\r\n## Weird Bug In GDNative{.block}\r\n\r\nA weird bug exists in the **Windows version of GDNative**, both in GodotSteam and Samsfacee's plug-in. Sometimes the **setRichPresence()** function will send the key as the value. It isn't consistent but happens enough to be noticeable and a pain.\r\n\r\nPlease note this bug *does not exist* in the pre-compiled module versions nor GDExtension version or the GDNative versions for Linux or OSX.\r\n\r\nThis behavior definitely seems to be a GDNative problem so we can't really fix it on our and an issue has been submitted to the Godot GitHub page.\r\n\r\nThankfully, **Furcifer** has shared some code that should help with this!\r\n\r\n```gdscript\r\nvar iteration = 0\r\nvar richPresenceKeyValue = []\r\nvar updatingRichPresence = false\r\n\r\nfunc callNextFrame(methodName, arguments = []):\r\n\tget_tree().connect(\"idle_frame\", self, methodName, arguments, CONNECT_ONESHOT)\r\n\r\nfunc updateRichPresence():\r\n\titeration = 0\r\n\trichPresenceKeyValue.clear()\r\n\t\r\n\taddRichPresence(\"numwins\", String(Game.getNumWins()))\r\n\taddRichPresence(\"steam_display\", \"#status_Ingame\")\r\n\r\n\tif not updatingRichPresence:\r\n\t\tupdatingRichPresence = true\r\n\t\tsetPresenceDelayed()\r\n\r\nfunc addRichPresence(key, value):\r\n\trichPresenceKeyValue.push_back([key, value])\r\n\tSteam.setRichPresence(key, value)\r\n\r\nfunc setPresenceDelayed():\r\n\tvar remaining = []\r\n\tfor tuple in richPresenceKeyValue:\r\n\t\tvar success = forceSetProperty(tuple[0], tuple[1])\r\n\t\tif not success:\r\n\t\t\tremaining.push_back(tuple)\r\n\t\r\n\trichPresenceKeyValue = remaining\r\n\t\r\n\tif not richPresenceKeyValue.empty():\r\n\t\titeration += 1\r\n\t\trecallSetPresenceDelayed() # recalls this function after a frame\r\n\telse:\r\n\t\tupdatingRichPresence = false\r\n\r\nfunc recallSetPresenceDelayed():\r\n\tUtil.callNextFrame(self, \"setPresenceDelayed\")\r\n\r\nfunc forceSetProperty(key : String, value : String) -> bool:\r\n\tfor i in 10:\r\n\t\tvar setval = Steam.getFriendRichPresence(STEAM_ID, key)\r\n\t\tif setval == key:\r\n\t\t\t#print(\"could not set key \", key, \" - iteration: \", iteration, \"\/\",i)\r\n\t\t\tSteam.setRichPresence(key, value)\r\n\t\telse:\r\n\t\t\treturn true\r\n\t\r\n\treturn false\r\n```\r\n\r\n## Additional Resources{.block}\r\n\r\n### Video Tutorials\r\n\r\nPrefer video tutorials? Feast your eyes and ears!\r\n\r\n[youtube: Setting Up Rich Presence](https:\/\/www.youtube.com\/watch?v=VCwNxfYZ8Cw&t=4762s){ data-author=\"FinePointCGI\" }\r\n\r\n### Example Project\r\n\r\n[Later this year you can see this tutorial in action with more in-depth information by checking out our upcoming free-to-play game Skillet on Codeberg.](https:\/\/codeberg.org\/godotsteam\/skillet) There you will be able to view of the code used which can serve as a starting point for you to branch out from."
Comments
Log in to post a comment
Licensed under the CC-BY license
See the full license details
Submitted by
Gramps
Table of contents
Compatibility
Works in Godot
3.x / 4.x
Tags
GodotSteam
steamworks
SteamĀ®
Share this tutorial
Share on Bluesky
Share on X / Twitter
or share this direct link:
https://thegodotbarn.com/contributions/tutorial/701/godotsteam-tutorial-rich-presence
Please wait ...
Okay
Okay
No
Yes
Okay