Labbah
Labbah

Reputation: 31

Steamworks.NET "Tried to Initialize the SteamAPI twice in one session!"

I am using Mirror with FizzySteamworks to integrate my Unity game to steam. My NetworkManager is initialized in the offline scene and is kept "DontDestroyOnLoad" to not shutdown the Steam API. The problem is that i get the following error once I leave a lobby:

Exception: Tried to Initialize the SteamAPI twice in one session!

To my knowledge, the problem is that my NetworkManager is a GameObject in the offline scene,so once I quit a session it will be a duplicated NetworkManager (However this is not prompted as an error, which is strange if you look at the NetworkManager.cs error exceptions). Therefore, once a second instance of the NetworkManager is being loaded, the new Steam API sees the duplicate and automatically removes the previous (correct) one. This can be seen in Awake() of the SteamManager.cs script:

protected virtual void Awake() {
    // Only one instance of SteamManager at a time!
    if (s_instance != null) {
        Destroy(gameObject); // <--- HERE
        return;
    }
    s_instance = this;

    if(s_EverInitialized) {
        // This is almost always an error.
        // The most common case where this happens is when SteamManager gets destroyed because of Application.Quit(),
        // and then some Steamworks code in some other OnDestroy gets called afterwards, creating a new SteamManager.
        // You should never call Steamworks functions in OnDestroy, always prefer OnDisable if possible.
        throw new System.Exception("Tried to Initialize the SteamAPI twice in one session!");
    }

How can I solve this? Note that the NetworkManager option "Persist Network Manager to offline scene" is deprecated and thus not available anymore.

Upvotes: 2

Views: 1379

Answers (1)

Burak Ekinci
Burak Ekinci

Reputation: 11

if you attached steam manager component into Network Manager gameobject(the gameobject which network manager component attached) it might create an issue. If it's the case then create a new gameobject on offline scene after that add steam manager component to this new gameobject, don't forget to remove steam manager componnet from Network Manager gameobject. I hope this fixes your issue.

Upvotes: 0

Related Questions