question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Enter Play Mode Settings' causes SteamManager to "load Steamworks DLL twice"

See original GitHub issue

Summary

Having ‘Project Settings > Editor > Enter Play Mode Settings’ enabled for quick playtests of the game causes the SteamManager class to fail every time after the first playtest.

Steps to reproduce

  1. Check the ‘Project Settings > Editor > Enter Play Mode Settings’ checkbox. Leave both options below unchecked (hence “do not reload domain or scene.”)
  2. Play the game, making sure to fire at least one SteamManager method (example: SteamManager.Initialized)
  3. Exit the play mode.
  4. Re-enter the play mode and fire any call to the SteamManager methods.

Expected result

Both calls that happen at step 2. and 4. succeed.

Actual result

An exception is observed:

Exception: Tried to Initialize the SteamAPI twice in one session!
Presenter.Domain.SteamManager.Awake () (at Assets/Scripts/Presenter/Domain/SteamManager.cs:144)
UnityEngine.GameObject:AddComponent()
Presenter.Domain.SteamManager:get_Instance() (at Assets/Scripts/Presenter/Domain/SteamManager.cs:39)
Presenter.Domain.SteamManager:get_Initialized() (at Assets/Scripts/Presenter/Domain/SteamManager.cs:52)
Presenter.DataManager.InitialLoader:Start() (at Assets/Scripts/Presenter/DataManager/InitialLoader.cs:39)

(Ignore the namespace, that is where I placed the SteamManager for my convenience)

Comment

Although Steamworks.NET documentation points to SteamManager.cs file (which looks like a raw link to a file in the repository,) I cannot find it in the repository here, so PR is not possible at this moment. Also, ‘disabling domain reload’ itself is an experimental feature of Unity (since 2019.3,) so I’d like to make sure if we’re really supporting it. But if we were to fix it the fix will look like the following:


I don’t know why the stack trace points to the end of the Awake() method, but I suspect the reason for crashes to be the s_EverInitialized flag being static. Anything static won’t be initialized back to their default value if “Domain Reload” is disabled like this case.
We should be able to fix it by adding the following method to SteamManager.cs.

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void InitOnPlayMode()
{
    Debug.Log("Resetting initialization status.");
    s_EverInitialized = false;
    s_Instance = null;
}

Tested with

Unity 2020.1.0b12 (commit 4aa0ee8, but the file in question does not exist.)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Clpsplugcommented, Jun 17, 2020

@rlabrecque, I just realized that my fix is never going to work. I misunderstood the naming convention of the version directives. Instead of

UNITY_VERSION_2019_3_OR_NEWER

it is

UNITY_2019_3_OR_NEWER

I will issue a hotfix to the SteamManager repository right away.

1reaction
Clpsplugcommented, Jun 13, 2020

I can’t really think of such use cases - it’s just my 2 cents, but I believe the sole purpose of developers shutting the play mode down in Unity3D is to ‘demolish’ that game session and start anew. Actually, if it were not for the experimental features in question, the context will never survive between sessions because the script domain is totally reset. So at least for using this code for Unity games, the persistent context does not make much sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Steamworks.NET crashes Unity 2017.2.0f3 · Issue #195
I experience crashes in the Unity editor - AFAIK, only after having hit PLAY at least once (and stopping the game again, so...
Read more >
Steamworks.NET "Tried to Initialize the SteamAPI twice in ...
I am using Mirror with FizzySteamworks to integrate my Unity game to steam. My NetworkManager is initialized in the offline scene and is...
Read more >
Loading Scene twice in play mode tests causes Editor to ...
Hi, I'm trying to write tests for a scene. Because a lot of my scene is already in place and I need to...
Read more >
Frequently Asked Questions
If your build is shutting down due to SteamAPI.Init() failing as the SteamManager script does by default, double check that you own the...
Read more >
UNITY Crash during Reentry.
I was making a "round the moon and back" prototype mission. Everytime the capsule reenters, unity crashes at around 71-70km height.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found