TUTOUNITYFR / Rich-Presence-Discord-Unity3D

Projet exemple d'utilisation de Rich Presence (Discord) dans Unity 3D.
27 stars 3 forks source link

Presence Manager disconnects when loading a scene where a presence manger is also present #4

Open SuperIllu opened 3 years ago

SuperIllu commented 3 years ago

If you create a Presence Manager from the prefab in a scene and load to a scene where also a presence manager is present, the PresenceManager will disconnect from discord. This also happens, if you reload the scene if a presence manager is set up in this scene. This happens because the instance persists through different scenes (DontDestroyOnLoad in Awake()) Awake() checks if a presence manager (instance) already exists, and if so calls Destroy(gameobject). This leads to calling the OnDisable() function. In an instance has been previously created, the second (later) instantiation will be destroyed and call:

void OnDisable() { Debug.Log("Discord: shutdown"); DiscordRpc.Shutdown(); } a possible solution is to replace with: void OnDisable() { if (instance == this) { Debug.Log("Discord: shutdown"); DiscordRpc.Shutdown(); } }

LuigisMansion commented 3 years ago

Just verified for myself that this solution indeed works.