Facepunch.Steamworks Wiki

Setting Up

If you're making a game you probably want the SteamClient.

This gives access to things like friends, achievements, stats, server lists etc.

Dlls

You need to copy us to your project to be able to use Steamworks.

Regular .net app

You'll need to put steam_api64.dll/steam_api.dll somewhere (depending on whether you're building 32bit/64bit)

Unity

If you're using Unity, open the release zip file and copy the Unity file into your project, anywhere in Assets (we usually put it in Assets/Plugins/Facepunch.Steamworks/.

The zip file already includes .meta files so that files the dlls are set up properly. The .meta files for the native dlls are set up in a way that mean that they're used on the right platforms and will get copied properly on build. You don't need to do anything special.

If you use old versions of Unity or have worked on your project for a long time, your Scripting Runtime might be set to the default .NET 2.0, you'll need to set it to .NET 4.x.

Initializing

To start up you just call SteamClient.Init with your appid.

If it can't initialize it'll throw an exception - so make sure you catch that and deal with it.

try { Steamworks.SteamClient.Init( 252490, true ); } catch ( System.Exception e ) { // Something went wrong! Steam is closed? }

Common reasons for exceptions are:

  • Steam is closed
  • Can't find steam_api dlls
  • Don't have permission to open appid

In Unity I'd recommend calling this in an Awake on an object with DontDestroyOnLoad called on it.

Running

Every frame or so you should call RunCallbacks.

This isn't needed if you left asyncCallbacks as true in Client.Init because it'll be called every frame anyway (in the background).

In Unity I'd recommend sticking it in an Update.

Using

You can make sure Steam is loaded and accessible using SteamClient.IsValid.

Here's some examples of other interfaces and functions to give you an idea of how to use/find stuff.

var playername = SteamClient.Name; var playersteamid = SteamClient.SteamId; SteamScreenshots.TriggerScreenshot(); Steamworks.SteamUserStats.SetStat( "deaths", value ); foreach ( var item in Steamworks.SteamInventory.Items ) { Debug.Log( $"{item.Def.Name} x {item.Quantity}" ); } foreach ( var player in SteamFriends.GetFriends() ) { Debug.Log( $"{player.Name}" ); }

Shutting Down

When you're done call SteamClient.Shutdown.

Steamworks.SteamClient.Shutdown();
Steam won't actually show that you've stopped playing the game at this point. It doesn't do that until the exe and any child processes are closed. It sucks, but that's the way it is.

This also means that in the Unity Editor it'll show as in game until you close the editor, but subsequent SteamClient.Init calls are needed and will work.

In Unity I'd recommend sticking it in an OnDisable, so that it gets called every time you stop playing.

Page Links


Special Pages


Wikis

?

Render Time: 31ms

DB GetPage 4
Generate Html 1
SaveChanges (1) 22
Render Body 0
Render Sidebar 1