Initialization and settings
Before your game can show a single mod, the SDK needs to know which game it is serving and where on the player's device it may keep content. Those answers live in the SDK settings, and the SDK reads them once, when it starts.
Most of the settings are one-time decisions your team makes during the integration and does not revisit: your game's identity, where mods go on disk, and how much bandwidth installs may use. A few switch on capabilities, such as analytics, dedicated server behavior, or premium mod protection. The storage location deserves the most thought, because it decides where players' mods and sign-in state sit on their devices for the life of your game.
The SDK starts once per session and stays up until your game quits. Teams using the prebuilt mod browser manage all of this from a settings page in the Unity editor, with no code beyond a single startup call.
Where settings live
| Approach | Where the values live | Use it when |
|---|---|---|
A Settings object | Your own code, passed to BootstrapUnity.Create | You call the core API directly |
The CurseForgeSettings asset | Project Settings > CurseForge Settings, saved in your project | You use CFUnity or the prebuilt browser |
Set every value before the SDK instance is created. The SDK keeps a reference to your Settings object and reads some fields again on every use, so do not change the object once the instance exists. The one supported runtime change is the premium public key, through ICFCore.PremiumMods.OverridePublicKey.
Initializing with the core API
How it works
- Build a
Settingsobject. Four fields are required:GameId,ApiKey,ModsDirectoryandUserDataDirectory. - Pass it to
BootstrapUnity.Create, which returns anICFCore. - Call
Initializewith anInitializationOptionsand two delegates. - Wait for a delegate. On success, every area member of
ICFCorebecomes available. On failure, the SDK stays uninitialized and the failure delegate receives a message. If your success delegate throws, the SDK treats it as a failure: it becomes uninitialized and runs the failure delegate too.
Make every call from Unity's main thread. Both delegates run on the main thread.
using Overwolf.CFCore.Base;
using Overwolf.CFCore.Base.Models;
using Overwolf.CFCore.Base.Models.Enums;
using Overwolf.CFCore.Unity;
using UnityEngine;
public class CurseForgeService : MonoBehaviour {
[SerializeField] private uint _gameId;
[SerializeField] private string _apiKey;
public ICFCore Core { get; private set; }
private void Awake() {
DontDestroyOnLoad(gameObject);
string root = Application.persistentDataPath;
Settings settings = new Settings {
GameId = _gameId,
ApiKey = _apiKey,
ModsDirectory = System.IO.Path.Combine(root, "mods"),
UserDataDirectory = System.IO.Path.Combine(root, "user_data"),
ModsDirectoryMode = ModsDirectoryMode.CFCoreStructure,
MaxConcurrentInstallations = 3
};
settings.Logger.Output = LogOutput.File | LogOutput.Console;
Core = BootstrapUnity.Create(settings);
}
private void Start() {
InitializationOptions options = new InitializationOptions {
UserContextId = "local"
};
Core.Initialize(
options,
() => Debug.Log("CurseForge initialized"),
(string error) => Debug.LogError($"CurseForge failed: {error}"));
}
}
Prebuilt UI: CFUnity.Initialize, which takes the CurseForgeSettings asset instead of a Settings object. See Initializing with CFUnity below.
The user context id
InitializationOptions.UserContextId names the local player whose state the SDK loads. It must not be empty or whitespace, or initialization fails. Calling Initialize without options uses the id local. Passing options without an id does not.
Installed mod files are stored once and shared by everyone who plays on the device. Each context id keeps its own state on top of them:
| Per-player state | What it means |
|---|---|
| Installed mods | Which mods this player has installed. A mod installed by one player does not appear for another |
| Session | The player's sign-in, kept between launches |
| Enabled flags | Which installed mods this player has turned on |
| Load order | This player's order for installed mods |
The session, enabled flags and load order are kept in the player's own folder under <user data directory>/<game id>/<context id>. The list of who installed which mod is kept in a shared library file in <user data directory>/<game id>.
Use one stable id per local player. On a single-player device, a fixed id such as local is enough. If your game supports several local profiles, give each its own id so their sign-ins and mod choices stay apart.
Choose the id before the first Initialize. Calling Initialize again with a different id reloads only the player's saved state, and when the new id has no saved state yet, the previous player's sign-in and mod choices stay loaded.
Repeated calls
| Situation | What happens |
|---|---|
Initialize while already initialized | Reloads the player's saved state for the given context id and checks a stored session with the server, then runs the success delegate. With invalid options, the SDK becomes uninitialized |
Initializing with CFUnity
CFUnity.Initialize takes the CurseForgeSettings asset, an optional function that supplies the player's platform sign-in token, and optional success and error delegates. It builds the Settings object from the asset, creates the SDK instance and initializes it.
Its success delegate runs later than the core API's. After the SDK initializes, CFUnity also fetches the current terms from CurseForge, and only then reports success. If fetching the terms fails, the error delegate runs instead. The CFUnity services, such as CFUnity.Catalog and CFUnity.Install, are available once the success delegate has run.
CFUnity uses the context id local. When the UNITY_STANDALONE_STEAM scripting define is set, it uses the player's Steam id instead, by calling SteamUser.GetSteamID(). The UI package does not reference Steamworks.NET, so with that define set the package does not compile as shipped.
The prebuilt browser calls CFUnity.Initialize for you when you initialize its CurseForgeUI component. See Mod browser.
Settings reference
These are the fields of Settings. Every field is public and set before you call BootstrapUnity.Create.
| Field | Default | What it does |
|---|---|---|
GameId | None | Your game id from the Developer Portal. Required |
ApiKey | None | Your API key from the Developer Portal, sent with every API request. Required |
ModsDirectory | None | The root folder for installed mods. Required |
UserDataDirectory | None | The root folder for per-player state and log files. Required |
ModsDirectoryMode | CFCoreStructure | The folder layout inside ModsDirectory. See Deciding how mods sit on disk |
Language | en | The language of the terms text the SDK fetches |
MaxConcurrentInstallations | 0 | How many installs run at once. Values below 1 count as 1 |
MaxConcurrentUploads | 0 | How many uploads run at once. Values below 1 count as 1 |
EnablePerformanceAndStabilityAnalytics | false | Lets the SDK report install outcomes. See Analytics |
EnableUserEngagementAnalytics | false | Lets your own engagement analytics calls send. See Analytics |
IsServer | false | Marks this instance as a game server. See Multiplayer and servers |
IsServerPcOnly | false | With IsServer, limits the server's mod queries to PC files, for servers that only accept PC players |
ModFilesRegexFilter | Everything except dotfiles | Which files in a local draft count as part of the mod, for change detection and publishing |
GameVersionTypeId | null | Not applied to any request. To filter by game version type, set it on the search filter instead |
UnmanagedMods | See below | Detection of mods placed on disk outside the SDK |
PremiumMods | See below | Verification of premium mod responses |
Logger | See below | Where the SDK writes its log |
The default value of ModFilesRegexFilter is the regular expression ^(?!\.).*.
Settings also has an ApiBaseUrl field, which the Unity SDK ignores. The Api Base Url field on the settings asset feeds it, so it has no effect either.
Sub-settings reference
Unmanaged mods
Field of UnmanagedMods | Default | What it does |
|---|---|---|
Enabled | false | Scans the mods directory at startup and registers folders not installed through the SDK as unmanaged mods |
ScanOneLevelUp | false | Also scans the parent folder of the mods directory. See below |
ScanOneLevelUp scans the parent folder in every directory mode. With CFCoreStructure, that parent is ModsDirectory itself. With the other two modes, it is the folder above ModsDirectory, and every folder beside your mods directory is registered as an unmanaged mod.
How unmanaged mods appear in the library is on Installing mods.
Premium mods
Field of PremiumMods | Default | What it does |
|---|---|---|
PublicKeyPem | Empty | The PEM-encoded RSA public key used to verify signed premium mod responses. When empty, verification is skipped |
Without a public key, premium ownership responses are accepted unverified. Set the key before you sell mods. See Monetization.
Logger
Field of Logger | Default | What it does |
|---|---|---|
Output | LogOutput.None | Where log lines go: nowhere, to log files, to the Unity console, or both |
History | 8 | How many rolled log files to keep, from 0 to 30. File output only |
MaxSizeInMB | 2 | The size at which a log file rolls over, from 2 to 10. File output only |
LogOutput is a flags enum: combine LogOutput.File and LogOutput.Console to write to both. Log files are written to a logs folder inside UserDataDirectory. Console output goes to the Unity console. The logger is read once, when the SDK instance is created. More on logging in Error handling.
The CurseForgeSettings asset
The UI package stores its settings in a CurseForgeSettings asset, shipped at Assets/Plugins/CurseForge/UI/Content/CurseForgeSettings.asset. Edit it under Project Settings > CurseForge Settings, or select the asset and edit it in the Inspector.
Most fields map one to one onto Settings and its sub-settings. Two are built for you: the asset sets ModsDirectory and UserDataDirectory from its storage location, as described in Storage location below. The asset also has fields that only the prebuilt browser and CFUnity read:
| Asset field | What it does |
|---|---|
| Use Installed Mods Management | Lets players enable, disable and reorder installed mods in the browser |
| Use Subscriptions | Turns on subscriptions in the browser and CFUnity, so the browser offers to sync a player's subscribed mods after sign-in |
| Allow Email Auth | When platform sign-in fails, lets the browser fall back to an email one-time code |
| Enable Version History | Lets players install older files of a mod from the browser |
| Logging Verbosity | Filters the console messages written by CFUnity and its services, shown only when the logger writes to the console. It does not affect the core SDK log |
The asset leaves GameVersionTypeId unset when its field is 0, and resets an empty language to en.
Storage location
The asset builds both directories from one storage location, placing mods and user_data folders inside it.
| Storage Path | Location in a build |
|---|---|
PersistentDataPath | Unity's Application.persistentDataPath. The default |
DataPath | Unity's Application.dataPath |
Custom | The path in Custom Storage Path |
In the editor, the asset uses its own editor storage setting instead, which defaults to a cfcore folder in your project directory. Mods installed while testing in the editor stay separate from a build's data on the same machine.
Your code can also call SetCustomStoragePath on the asset, which sets the custom path and switches the storage mode to Custom. In the editor, the editor storage setting still applies, so the call has an effect only in a build.
Getting help
For your game id and API key, or to have a capability enabled for your game, contact cfforstudios@overwolf.com. Game configuration is in the Developer Portal at console.curseforge.com.