rlabrecque / Steamworks.NET

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

Cannot launch from Steam client #142

Closed Bankler closed 7 years ago

Bankler commented 7 years ago

I have changed the appId in steam_appid.txt, which resides in my main Unity project folder (next to assets etc). I have changed SteamManager.cs:72 to

if (SteamAPI.RestartAppIfNecessary(new AppId_t(my_appid_here))) {

The game can Debug.Log print my Steam user name, as shown in the tutorial.

First time I press Build and run, the game launches, but cannot bring up steam overlay with shift+tab.

If I close and run again, a Steam window pops up and prompts me to select installation directory "D:\Steam". I press Ok. It installs (but doesn't really copy anything, just lights up my game in the Steam Library).

If I again start the .exe, or try to launch the game from the Steam client (i.e the Library), I always get the message "Failed to start game (invalid app configuration)".

If I put the steam_appid.txt in the built game folder, I can start the .exe (still no steam overlay). It says ("Now playing") on the game in the Library. (so it recognizes it at least)

If I start it through the Steam Library I just get previously mentioned error message.

I tried putting the build in its SteamApps folder in Steam, but it made no differance.

steamfail 1)* Is there a way I can start a standalone build and use the Steam Overlay?

2)* Should I be able to start the game from the Steam Library?

3)* If yes, should the steam_appid.txt file be next to the .exe or do I only need that when starting the .exe manually?

4)* Again, if yes, is it important that I put the build in the steamapps/common/my_game folder, or can the build reside in my usual UnityProject/Builds folder?

At one point during my attempts, after a build-and-run (as suggested in another thread) I actually got the Steam overlay to work. But I cannot make that happen again. That confuses me.

Best regards Bankler

rlabrecque commented 7 years ago

Hey @Bankler

1)* Is there a way I can start a standalone build and use the Steam Overlay?

If you launch the game from a shortcut in your steam library which points to the standalone build in your output folder then the overlay will be injected as the game starts.

I think if you use "Build and Run" in Unity that might work too, but only if you've already played in the editor in that session. (Because SteamAPI.Init() gets called, which injects the overlay, then build and run spawns your game as a child process and the overlay gets automatically injected into it.)

2)* Should I be able to start the game from the Steam Library?

Only if you've uploaded your game to steam and it's being correct downloaded into your steamapps/common folder. Your launch parameters in the Steamworks backend may be incorrect as well. (Don't forget to publish the changes!)

3)* If yes, should the steam_appid.txt file be next to the .exe or do I only need that when starting the .exe manually?

The steam_appid.txt is only required when testing locally, it's generally not recommended to ship it on steam to customers.

4)* Again, if yes, is it important that I put the build in the steamapps/common/my_game folder, or can the build reside in my usual UnityProject/Builds folder?

So, If you use SteamAPI.RestartAppIfNecessary, without having a steam_appid.txt then your game is literally doing a complete shutdown with Application.Quit() and then steam relaunches it once it quits. This relaunch is literally the exact same thing as double clicking the game in your steam library, so it kind of depends how you want to work. If you're testing with the overlay then having your builds output to your steamapps/common folder and just launching from your regular steam library icon may be best. Otherwise one of the other options above might be better.

Bankler commented 7 years ago

Thanks! I Appreciate the quick reply!

Only if you've uploaded your game to steam and it's being correct downloaded into your steamapps/common folder. Your launch parameters in the Steamworks backend may be incorrect as well. (Don't forget to publish the changes!)

Ok, this might be the problem then. So I have to upload it once before I can run it from Steam? That makes sense. After I've uploaded it once, can I make new local builds and put them in steamapps/common/my_game folder (overwriting the old build), or do I have to upload everytime I make changes? If I want to test features that require the Steam overlay that is.

(I realize this might be basic questions, sorry for that. Just totally new concepts for me)

NKnusperer commented 7 years ago

Btw you dont need a steam_appid.txt, setting it as an environment variable from within you game like this also works:

private void SetSteamId(int steamId)
{
    Environment.SetEnvironmentVariable("SteamAppId", steamId.ToString());
    Environment.SetEnvironmentVariable("SteamGameId", steamId.ToString());
}
Bankler commented 7 years ago

Got everything to work now. Big moment first time seeing the game launching from Steam! :)

Btw, thank you so much @rlabrecque for the detailed reply. That explained perfectly why I had gotten the overlay to work once and only once. Jjust like you said, if I had run the game inside the editor once before the build-and-run, the overlay worked.

And as a reply to my own follow-up question. Yes, you can overwrite the build in the steamapps folder with build output from the Unity editor. The game will still start from Steam with the new updates, and the overlay will of course still work. You only need to upload and download it "for real" one time.