Jump to content

Mod Loader/Reference/Settings API

From WikiName

Players can change your plugin's options from the game's Mod Settings menu. The loader provides toggles, sliders, and buttons. Your plugin decides what each option does. This API is available in Mod Loader 0.6.43 and later.

Make a settings tab

First create your BepInEx config entries, then pass them to ModSettingsApi.Register on Unity's main thread. The first argument is a stable ID for your tab; the second is the name players see. Keep the returned tab so you can remove it when your plugin unloads.

using System;
using BepInEx;
using BepInEx.Configuration;
using DressmakerMods;

[BepInPlugin("example.settings", "Settings Example", "1.0.0")]
[BepInDependency("yuu.dressmaker.mods", "0.6.43")]
public sealed class SettingsExample : BaseUnityPlugin
{
    private ConfigEntry<bool> enabled;
    private ConfigEntry<float> strength;
    private ModSettingsTab tab;

    private void Awake()
    {
        enabled = Config.Bind("General", "Enabled", true);
        strength = Config.Bind("General", "Strength", 0.5f);
        tab = ModSettingsApi.Register("example.settings", "Example",
            new ModToggleSetting("Enabled", "Turn the effect on or off.", enabled),
            new ModSliderSetting("Strength", "Set the effect strength.", strength, 0f, 1f),
            new ModActionSetting("Apply", "Apply the current settings.", Apply));
    }

    private string Apply() => "Settings applied.";
    private void OnDestroy() => tab?.Dispose();
}

The example adds an Enabled switch, a Strength slider, and an Apply button. Config.Bind saves the switch and slider in your plugin's BepInEx config file. Pressing Apply calls Apply(); the text it returns appears beside the button. A button does not save a value by itself.

Choose a control

Control Use it for Example
Toggle An on/off option stored as ConfigEntry<bool>. new ModToggleSetting("Enabled", "Turn the effect on or off.", enabled)
Slider A number stored as ConfigEntry<float>. Give it a minimum and maximum. new ModSliderSetting("Strength", "Effect strength.", strength, 0f, 1f)
Action A button that runs a Func<string> when clicked. new ModActionSetting("Apply", "Use these settings now.", Apply)

Each control has a short title and a description shown to the player. A slider can also use wholeNumbers: true for steps of one, or suffix: "%" to show units. The minimum and maximum must be finite numbers, and the maximum must be larger. The menu shows four controls per page if you add more than four.

Apply changes while the game is running

BepInEx saves toggle and slider values, but it cannot know how to update your effect. If a change should take effect immediately, subscribe to the config entry's SettingChanged event. Unsubscribe when the plugin unloads:

private void Awake()
{
    enabled = Config.Bind("General", "Enabled", true);
    enabled.SettingChanged += OnEnabledChanged;
    // Register the tab after binding your entries.
}

private void OnEnabledChanged(object sender, EventArgs e)
{
    SetEffectEnabled(enabled.Value);
}

private void OnDestroy()
{
    if (enabled != null) enabled.SettingChanged -= OnEnabledChanged;
    tab?.Dispose();
}

This shows the event handling; add it to the full plugin above rather than copying a second Awake method. Replace SetEffectEnabled with your own code.

C# signatures

ModSettingsTab ModSettingsApi.Register(string id, string title, params ModSetting[] settings)
ModToggleSetting(string title, string description, ConfigEntry<bool> entry)
ModSliderSetting(string title, string description, ConfigEntry<float> entry,
    float minimum, float maximum, bool wholeNumbers = false, string suffix = "")
ModActionSetting(string title, string description, Func<string> action)

Register rejects an empty ID or title, a duplicate ID, and an empty or invalid settings list. Use an ID based on your plugin's ID so it stays unique. Dispose the returned ModSettingsTab when the plugin unloads.

Shared accessibility settings

AccessibilitySettings exposes the loader's existing config entries so another plugin can read or reuse them:

AccessibilitySettings.StillSewingGuides
AccessibilitySettings.SoftSewingGuideColors
AccessibilitySettings.StillCuttingArrow
AccessibilitySettings.StillPatternWarnings
AccessibilitySettings.SewingView

Brightness and Saturation remain in the API for compatibility, but are obsolete and unused.

Back to the Mod Loader guide