'Enter Play Mode Settings' causes SteamManager to "load Steamworks DLL twice"
See original GitHub issueSummary
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
- Check the ‘Project Settings > Editor > Enter Play Mode Settings’ checkbox. Leave both options below unchecked (hence “do not reload domain or scene.”)
- Play the game, making sure to fire at least one SteamManager method (example:
SteamManager.Initialized
) - Exit the play mode.
- 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:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
@rlabrecque, I just realized that my fix is never going to work. I misunderstood the naming convention of the version directives. Instead of
it is
I will issue a hotfix to the SteamManager repository right away.
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.