So I am using the Steamworks API / Steamworks.NET for the first time. It says in numerous places, including the initial tutorial, Make sure Steam is initialized. It does not, however, explain why, and I’m struggling to see a reason.
From what I can tell, you can’t play the game without signing in to Steam, and you can sign in whether you’re offline or online, plus if you try and close Steam while my game is running, the game is closed as well, so what’s the benefit? As far as I an tell, Steam has to be initialized for your game to run, unless there is a difference between their definition of initialized and being signed in?
I am assuming it’s trying to protect you from something but I am not sure what?
Link to the Steamworks API I’m using here.
It’s relevant because I’m trying to set up cloud saves, and affects how I approach everything.
Still don’t fully understand this, however, calling SteamManager.Initialized in the Awake() function caused errors for me, but in Start() it doesn’t. Weird. So I guess there is a reason to use it. It would be great to understand the ‘why’ though.
SteamManager uses the singleton pattern, where a static reference is kept. If you look at the script, it initializes itself in the Awake method. s_instance = this;
Unity has a call order. So Awake is first then Start.
If your script executes their API in Awake
too, you might encounter that the SteamManager
is not initialized. Because the Awake
has not been triggered yet for that Manager script. Or one of your behaviours does, but the other doesn’t. Because call order.
In Start, it ‘should’ve’ initialized already. There should be a SteamManager
instance. But you cannot be a 100% certain whether it has an instance or not. Hence that you check for whether SteamManager.Initialized
.
Let’s say it isn’t initialized for some reason. A bug or some other reason. And you’re not checking Initialized but do call their API. You’ll start getting exceptions. When an exception is thrown, it’ll stop executing the rest of the code. Potentially not running anything you might’ve needed.
When you do check you can easily write some form of handling the situation. Like popping up an error message to try again or instantiate an instance of it yourself (which shouldn’t be necessary in this case).
So yeah checking for Initialized on a singleton pattern manager before calling its API is normal.
Edit: I have no clue about SteamManager and I haven’t used it myself. But this is what I observe from reading their SteamManager script.
Mate that was super helpful, thanks! Yeah I actually did get an error trying to check if it was initialized on Awake. It caused a whole bunch of errors that were not related to SteamManager at all.
And now I’m getting some crazy other errors, possibly related to SteamManager, but not according to the logs. The weird thing is, the game runs perfectly fine in Unity, but builds are crashing. It says the problem is the menu system but the only code I’ve changed is saving and loading, I suspect caused by SteamManager. I tried changing the script execution order after your message thinking that might fix it, but nope. This is very confusing, never seen such strange behaviour differences between editor and build when it should be the same.
Edit: Seems as though the issue is to do with their own script not initializing properly and looks like it may be a problem with the way their files are set up currently