Licers

← All articles

UnityC#GamesLicensingTutorial

How to Protect a Unity Game You Sell Outside Steam

Licers Team · 2026-11-24

To protect a Unity game you sell outside Steam, give each buyer a license key and check it when the game starts. Limit how many computers a key works on, verify that the server's answer is signed, and remember a good check so the game still opens offline. It won't stop a determined cracker, and nothing will. It does stop the download link and the shared key, which is where most copies come from.

Do you need it?

Be honest about this first.

Steam keys are a different thing. Valve lets you sell them in other shops, but they activate the game on Steam.

Step 1: Install the package

Add Licers with NuGetForUnity, or copy Licers.dll from the package's lib/netstandard2.0 folder into Assets/Plugins. It is plain managed code for Unity 2018.1 and later, on desktop and mobile.

Create a free Licers account, add your game as a product, and copy your public key and product id from the Integration page.

Step 2: A gate for your first scene

Put this on an object in a small start scene. It checks the saved key, and shows your activation panel when there is none.

using System;
using System.Globalization;
using Licers;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LicenseGate : MonoBehaviour
{
    const int GraceDays = 14;   // how long a checked player may stay offline

    public GameObject activationPanel;   // your key box and button

    static readonly LicenseClient Client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions
    {
        ProductId = "YOUR_PRODUCT_ID",   // refuses keys for your other games
        AppVersion = "1.0.0",            // shows in Analytics
    });

    void Start()
    {
        activationPanel.SetActive(false);
        string key = PlayerPrefs.GetString("license", "");
        if (key == "") ShowPanel("Enter your license key.");
        else Activate(key);
    }

    // Also call this from your Activate button.
    public async void Activate(string key)
    {
        key = key.Trim();
        try
        {
            // Unity's own id works on every platform, including mobile.
            var result = await Client.ValidateAsync(key, hwid: SystemInfo.deviceUniqueIdentifier);
            if (!result.Valid) { ShowPanel(result.Error); return; }

            PlayerPrefs.SetString("license", key);
            PlayerPrefs.SetString("checked", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));
            PlayerPrefs.Save();
            SceneManager.LoadScene("Game");
        }
        catch (NetworkException)
        {
            // No internet is not the same as no license.
            if (key == PlayerPrefs.GetString("license", "") && CheckedRecently()) SceneManager.LoadScene("Game");
            else ShowPanel("Could not reach the server. Check your connection.");
        }
        catch (LicenseException e)
        {
            // A forged answer, or a key for another of your games.
            ShowPanel(e.Message);
        }
    }

    static bool CheckedRecently()
    {
        if (!DateTime.TryParse(PlayerPrefs.GetString("checked", ""), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var seen)) return false;
        var age = DateTime.UtcNow - seen;
        return age >= TimeSpan.Zero && age < TimeSpan.FromDays(GraceDays);
    }

    void ShowPanel(string message)
    {
        Debug.Log(message);   // show it in your panel
        activationPanel.SetActive(true);
    }
}

PlayerPrefs can be edited, and that is fine here. A player who changes the saved date gets more days offline. They don't get a valid key.

Step 3: Sell the keys

Set the device limit to 2 or 3. People have a desktop and a laptop, and they replace them. In the customer portal they can free an old device without writing to you.

DLC and editions

Add entitlements to a key, such as {"dlc1": true}, and read them from the same answer:

if (result.Feature("dlc1") is true) UnlockDlc();

They are part of the signed answer, so editing a save file doesn't unlock anything.

Make removing the check harder

Don't punish your players

Never interrupt a running game. Give offline players a grace period. Keep the message clear, with a way to reach you. Pirated copies have no checks in them, so whatever friction you add is felt only by people who paid.

The Unity page has the offline license file version, for machines that never go online.

Frequently asked questions

How do I stop people copying my Unity game?

Give each buyer a key, check it online with a signed answer, and limit the devices per key. That stops shared downloads and shared keys. Building with IL2CPP makes removing the check harder, but no method stops every cracker.

Can I use license keys on itch.io?

Yes. Create the keys in bulk, export them, and give the list to the shop or send a key after each sale. Your game checks the key itself, so it doesn't matter where it was bought.

Does the license check work in WebGL builds?

Not directly. A browser game can't keep the check out of the player's reach, so verify the license on your own server and serve the game from there.

Can a Unity game check a license without internet?

Yes, with a signed license file made for that device. The game verifies it with the public key inside the build and nothing is sent.

Related guides

How to Add License Keys to a C# Desktop App (WPF and WinForms)

A complete example for WPF and WinForms. Check the key at startup, ask for one when there is none, remember it, and let paying customers keep working when they are offline.

How to Sell Software With Stripe and Deliver License Keys Automatically

Stripe takes the money but does not know what a license key is. Two ways to close the gap: a ready-made connection, or your own webhook, with the edge cases that bite.

How to License and Sell an Electron App

Electron apps ship as readable JavaScript, so where you put the license check matters. Complete main process code, what it stops, and what it does not.

Protect your software with Licers

Signed validation, floating licenses, offline files, and more — free to start.

Get started free