Add license keys to a Unity game or tool

To add license keys in Unity, install the Licers package with NuGetForUnity, create a LicenseClient with your public key, and call ValidateAsync with SystemInfo.deviceUniqueIdentifier as the device id. It works in Unity 2018.1 and later on desktop and mobile.

Updated by the Licers team

Install

  1. Add Licers with NuGetForUnity, or copy Licers.dll from the package’s lib/netstandard2.0 folder into Assets/Plugins.
  2. In Project Settings → Player, use .NET Standard 2.1 or .NET Framework API compatibility.
  3. Create a free account, add your game as a product, and copy the public key and product id.

Check a key

LicenseGate.cs
using Licers;using UnityEngine; public class LicenseGate : MonoBehaviour{    static readonly LicenseClient Client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions    {        ProductId = "YOUR_PRODUCT_ID",   // rejects keys for your other products        AppVersion = "2.4.1",    });     // Call from your "Activate" button.    public async void Activate(string key)    {        try        {            // Unity's own id works on every platform, including mobile.            var result = await Client.ValidateAsync(key, hwid: SystemInfo.deviceUniqueIdentifier);            if (!result.Valid) { ShowMessage(result.Error); return; }             PlayerPrefs.SetString("license", key);   // so players type it once            UnlockGame(fullVersion: result.Feature("full") is true);        }        catch (SignatureException) { ShowMessage("The license server could not be verified."); }        catch (NetworkException)   { ShowMessage("Could not reach the server. Check your connection."); }    }}

What it is good for

  • Games sold outside a store: your own site, itch.io or Gumroad, where there is no built-in DRM.
  • Editor tools and asset packs: one key per seat, with the device limit you choose.
  • Closed betas: issue keys with an expiry date and revoke a leaked one.
  • DLC: add entitlements to a key, such as {"full": true, "dlc1": true}.

WebGL builds cannot make these requests directly. Check licenses on your own server there.

Play without internet: offline license files

Show SystemInfo.deviceUniqueIdentifier to the player, create a .lic file for that device under License keys → ⋯ → Offline license file, and read it from the game’s data folder. Nothing is sent.

OfflineGate.cs
using System.Collections.Generic;using System.IO;using Licers;using UnityEngine; public static class OfflineGate{    public static bool Check()    {        // Pass the same device id you show to the player.        string device = SystemInfo.deviceUniqueIdentifier;        string path = Path.Combine(Application.persistentDataPath, "license.lic");        try        {            var lic = OfflineLicense.Verify("YOUR_PUBLIC_KEY", path, hwid: device, expectedProductId: "YOUR_PRODUCT_ID");            var features = lic["features"] as Dictionary<string, object>;            return features != null && features.TryGetValue("full", out var full) && full is true;        }        catch (SignatureException) { Debug.Log("The license file is missing, damaged or was edited."); }        catch (InvalidLicenseException e) { Debug.Log("License file refused: " + e.Message); }        return false;    }}

Handle every outcome

What happenedWhat your app should do
The key is expired, revoked, blocked or over its device limitShow the message the server sent. You can reword every one of them on the Custom Messages page.
The answer has a bad signature or an old nonceRefuse. Somebody is faking the server.
The server cannot be reached, or returns a 5xx errorRetry, or allow a grace period since the last good check. Being offline is not the same as being unlicensed.

Questions and answers

Does it work with IL2CPP?

The library is plain .NET Standard 2.0 code with no native dependencies.

Will this stop my game being cracked?

It stops shared keys, key generators and fake license servers. Someone who patches your build can still remove the check, so treat licensing as one layer.

Can players use a key on two computers?

Yes. Set the device limit per key, and let players free an old device themselves in the customer portal.

What does it cost?

Nothing today. Every feature is free and unlimited: products, keys, devices, validations, offline files and floating seats. See pricing.