Skip to main content

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​

ApproachWhere the values liveUse it when
A Settings objectYour own code, passed to BootstrapUnity.CreateYou call the core API directly
The CurseForgeSettings assetProject Settings > CurseForge Settings, saved in your projectYou 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

  1. Build a Settings object. Four fields are required: GameId, ApiKey, ModsDirectory and UserDataDirectory.
  2. Pass it to BootstrapUnity.Create, which returns an ICFCore.
  3. Call Initialize with an InitializationOptions and two delegates.
  4. Wait for a delegate. On success, every area member of ICFCore becomes 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 stateWhat it means
Installed modsWhich mods this player has installed. A mod installed by one player does not appear for another
SessionThe player's sign-in, kept between launches
Enabled flagsWhich installed mods this player has turned on
Load orderThis 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​

SituationWhat happens
Initialize while already initializedReloads 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.

FieldDefaultWhat it does
GameIdNoneYour game id from the Developer Portal. Required
ApiKeyNoneYour API key from the Developer Portal, sent with every API request. Required
ModsDirectoryNoneThe root folder for installed mods. Required
UserDataDirectoryNoneThe root folder for per-player state and log files. Required
ModsDirectoryModeCFCoreStructureThe folder layout inside ModsDirectory. See Deciding how mods sit on disk
LanguageenThe language of the terms text the SDK fetches
MaxConcurrentInstallations0How many installs run at once. Values below 1 count as 1
MaxConcurrentUploads0How many uploads run at once. Values below 1 count as 1
EnablePerformanceAndStabilityAnalyticsfalseLets the SDK report install outcomes. See Analytics
EnableUserEngagementAnalyticsfalseLets your own engagement analytics calls send. See Analytics
IsServerfalseMarks this instance as a game server. See Multiplayer and servers
IsServerPcOnlyfalseWith IsServer, limits the server's mod queries to PC files, for servers that only accept PC players
ModFilesRegexFilterEverything except dotfilesWhich files in a local draft count as part of the mod, for change detection and publishing
GameVersionTypeIdnullNot applied to any request. To filter by game version type, set it on the search filter instead
UnmanagedModsSee belowDetection of mods placed on disk outside the SDK
PremiumModsSee belowVerification of premium mod responses
LoggerSee belowWhere 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 UnmanagedModsDefaultWhat it does
EnabledfalseScans the mods directory at startup and registers folders not installed through the SDK as unmanaged mods
ScanOneLevelUpfalseAlso 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 PremiumModsDefaultWhat it does
PublicKeyPemEmptyThe PEM-encoded RSA public key used to verify signed premium mod responses. When empty, verification is skipped
danger

Without a public key, premium ownership responses are accepted unverified. Set the key before you sell mods. See Monetization.

Logger​

Field of LoggerDefaultWhat it does
OutputLogOutput.NoneWhere log lines go: nowhere, to log files, to the Unity console, or both
History8How many rolled log files to keep, from 0 to 30. File output only
MaxSizeInMB2The 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 fieldWhat it does
Use Installed Mods ManagementLets players enable, disable and reorder installed mods in the browser
Use SubscriptionsTurns on subscriptions in the browser and CFUnity, so the browser offers to sync a player's subscribed mods after sign-in
Allow Email AuthWhen platform sign-in fails, lets the browser fall back to an email one-time code
Enable Version HistoryLets players install older files of a mod from the browser
Logging VerbosityFilters 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
note

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 PathLocation in a build
PersistentDataPathUnity's Application.persistentDataPath. The default
DataPathUnity's Application.dataPath
CustomThe 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.