Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Integrating Steamworks.Facepunch

TheYellowArchitect edited this page Apr 9, 2021 · 16 revisions

Follow this pretty much
https://wiki.facepunch.com/steamworks/Setting_Up

===========================

To rephrase the above:

  1. Download the releases
    https://github.com/Facepunch/Facepunch.Steamworks/releases
  2. Unzip it
  3. Paste it onto your project, into an appropriate folder
  4. "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."
    Edit -> Project Settings -> Player -> Other Settings -> Configuration -> Scripting Runtime Version -> .NET 4.x Equivalent
  5. Create a gameobject called "SteamManager" to exist on the first scene of the game
  6. Create a script called "SteamManager" to be attached on the above gameobject
  7. The code for this script/class:
using System;
using Steamworks;
using UnityEngine;

public class SteamManager : MonoBehaviour
{
	//This is literally a singleton.
	public static SteamManager globalInstance;

	//This boolean exists because you may want a build to not use Steam.
	//Without this, every build will try to open steam, or bug heavily lmao
	public bool steamEnabled;

	//Since it is on Awake, it runs before Start() of other gameobjects :)
        //So, other steam logic scripts will be able to check if steam is active, without race conditions issues.
	void Awake()
	{
		//Steam disabled aka normal build
		if (steamEnabled == false)
		{
			Destroy(this);
			return;
		}



		globalInstance = this;

		//With this, you ensure no bugs happen ;)
		DontDestroyOnLoad(this);

		try
		{
			SteamClient.Init(480);//See 480 number at the bottom.
		}
		catch (Exception e)
		{
			BeardedManStudios.Forge.Logging.BMSLog.LogException("Steam Client could not be initialized");
			throw e;
		}
	}
	
	//Every frame or so you should call RunCallbacks.
	void Update ()
	{
		Steamworks.SteamClient.RunCallbacks();
	}

       //====================================================
       //==Ensuring steam overlay/connection properly stops==
       //====================================================

	private void OnApplicationQuit()
	{
		SteamClient.Shutdown();
	}

	private void OnDestroy()
	{
		SteamClient.Shutdown();
	}

	void OnDisable()
	{
		SteamClient.Shutdown();
	}
}

==========

The 480 number above, is the app ID of your game. 480 is the default spacewar, for testing. But you should use your own. This means having paid the steam fee/purchased a steam store page, and going to https://partner.steamgames.com/ and logging in. It should be next to the title of your game, in a parenthesis.
For example:

Spacewar(480)

==========

Try testing the above code (don't forget to put steamEnabled = true), by building a build and running it with Steam open.
It is unknown if it will work, as the proper way is to upload to Steam and download the build from Steam, like players do.
See next part ;)

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Forge Networking Alloy
Steamworks
Clone this wiki locally