rlabrecque / Steamworks.NET

Steamworks wrapper for Unity / C#
http://steamworks.github.io
MIT License
2.84k stars 371 forks source link

Getting unexpected "Tried to Initialize the SteamAPI twice in one session!" #657

Open WildRikku opened 6 days ago

WildRikku commented 6 days ago

I use Rich Presence in an OnDisable() to clear a text when a scene is unloaded. For a reason I cannot figure out, this causes SteamManager to throw the error for double initialization.

a) Am I safe to just comment out that error? I considered it a warning for bad coding style but I followed the recommendation there, which b) might be outdated, as only using OnDisable() seems to no longer be sufficient.

This is in Unity 2021.3.39f1. SteamManager creates its GameObject and Component itself in the scene in question. I use the Enter Play Mode options with both reloads turned off.

JamesMcGhee commented 3 days ago

SteamManager.cs is really more of an example script You would typically be best to author your own script to handle initialization and running callbacks

For example, if you want to use Steam Input you would also want to RunInput, you might want to fetch leaderboard IDs, etc. all in that same process.

For our toolkit (built on top of Steamworks.NET) we don't actually like to use a MonoBehaivour to run callback or input at all rather we use a background worker. This eliminates quite a few issues including the problem of it being a GameObject in a scene that needs to be persisted.

Our toolkit has a free and open source "lite" version if you want to look at how we did it or use it as is https://github.com/heathen-engineering/Toolkit-for-Steamworks-Foundation

Being a toolkit it does a lot ... if your only interesting in the initialization and running callbacks part check out the API.App.cs https://github.com/heathen-engineering/Toolkit-for-Steamworks-Foundation/blob/main/Unity/com.heathen.steamworksfoundation/Runtime/API.App.cs

Again it does more than just init Steam client it also has logic for Steam Game Server and a few other bits but might be handy for you