BepInEx / BepInEx.ConfigurationManager

Plugin configuration manager for BepInEx
https://www.patreon.com/ManlyMarco
GNU Lesser General Public License v3.0
227 stars 54 forks source link

Entries are being orphaned #63

Closed RyanHx closed 1 year ago

RyanHx commented 1 year ago

BepInEx 5.4.21 x64

I'm making a plugin that lets the user assign a label to an object and saving their input using BepInEx's config manager:

input = GUILayout.TextField(input);
if (GUILayout.Button("Submit"))
{
    Plugin.ConfigInstance.TryGetEntry(
        $"World.{guid}",
        storageIndex.ToString(),
        out ConfigEntry<string> entry
    );
    if (entry != null)
    {
        entry.Value = input;
    }
    else
    {
        Plugin.ConfigInstance.Bind($"World.{guid}", storageIndex.ToString(), input);
    }
    this.enabled = false;
}

I have SaveOnConfigSet set to true and tried a couple of test submissions which saved to the config file successfully:

[World.51cec5e8-76b4-4926-a00c-f3f936d14233]
# Setting type: String
# Default value: 1234
18890 = 1234

# Setting type: String
# Default value: test2
18887 = test2

When the player later hovers their crosshair over this object I hook the method that gets the "Interact" HUD text and add their label to it:

Plugin.ConfigInstance.TryGetEntry(
    $"World.{guid}",
    boxIndex.ToString(),
    out ConfigEntry<string> entryMaybe
);
if (entryMaybe != null && !entryMaybe.Value.IsNullOrEmpty())
{
    __result += $"\n{entryMaybe.Value}";
}

All of this works fine during a single play session. However when I restart the game the Entries property inside the ConfigFile is empty, and both entries have been moved to OrphanedEntries. How can I prevent this from happening? I read that entries are only orphaned if Bind isn't called on them, but I use that method to create them and they're saved, should they not be loaded back into Entries the next time I start the game? Since all the values are set at runtime I can't Bind everything inside my plugin Awake method, so I'm not sure how to keep them 'active' so to speak. Any help would be greatly appreciated!

RyanHx commented 1 year ago

Moving the issue over to the main BepInEx repo as it's not the config manager gui.