discord / gamesdk-and-dispatch

Public issue tracker for the Discord Game SDK and Dispatch
22 stars 7 forks source link

How to manually shutdown / end discord gamesdk? #126

Closed mastef closed 3 years ago

mastef commented 3 years ago

When using the Discord GameSDK with the UnityEditor, the presence is not cleared up the moment the UnityEditor is exiting the play mode. Also when re-starting the Playmode, the Discord presence is still stuck, and doesn't receive the updates from the new session.

For this purpose it would be beneficial to call something like Discord.Shutdown() manually ( e.g. in OnDisable() of my gameobject ) to clear the discord state.

Tried with Activity.clearActivity() or discord.Dispose() but that doesn't fully clear the game state in Discord - the user still shows up as "Playing Gamename" and further updates from a new session are ignored until either restart of Discord or UnityEditor.

Another use-case is to use this method when an error happened and to clean up the connection properly.

In the RPC SDK it seems that there was a "shutdown" method for this.

shraa1 commented 3 years ago

Personally, my unity editor closed when I called Dispose in OnApplicationQuit I think. Also I think this issue persists for the build player as well, not just the editor.

shraa1 commented 3 years ago

Actually using the Dispose causes a crash, not a graceful exit. The stack trace is huge.

mastef commented 3 years ago

What I've done is cleaning up the GameObject it is attached to with discord.Dispose().

image

Everything with the discord code is wrapped in a try{}catch(){} anyway, with the catch code destroying the object. Then OnDisable is called.

Since there are unexpected crashes, like discord sdk crashing if there's no discord running in the background, although it was initialized with the Discord.CreateFlags.NoRequireDiscord option. Or if the user closes Discord while playing the game, etc. We don't want any of this to bubble up to the game.

mastef commented 3 years ago

Related issue https://github.com/discord/discord-rpc/issues/13

Variiuz commented 3 years ago

Maybe the RunCallbacks() function doesnt execute between the ClearActivity and Dispose?

mastef commented 3 years ago

So far it seems that calling discord.Dispose() works well.