Your first working plugin
The Mycopunk mod template already contains a small plugin. It does not change the game yet. It writes a message to the BepInEx log, which is enough to check that the project builds and the game loads it.
Complete Project Setup before continuing.
The plugin class
Open Plugin.cs. The template starts with this class:
using BepInEx;
using BepInEx.Logging;
namespace MycopunkModTemplate;
[MycoMod(null, ModFlags.IsClientSide)]
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
internal new static ManualLogSource Logger;
private void Awake()
{
Logger = base.Logger;
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
}
}The important parts are:
BepInPlugingives BepInEx the plugin's GUID, name, and version.MycoModregisters the assembly as a Mycopunk mod. The template marks it as client-side.BaseUnityPluginprovides the BepInEx plugin lifecycle and logger.Awakeruns when BepInEx loads the plugin.
MyPluginInfo is generated from the project settings during the build. You do not need to create that class yourself.
Change the log line so it is easy to recognize:
Logger.LogInfo("My first Mycopunk mod loaded successfully!");Build the plugin
Build from your IDE, or run this from the project directory:
dotnet buildA Debug build is written to:
bin/Debug/netstandard2.1/The DLL name comes from AssemblyName in the .csproj file. For example, an assembly named MyFirstMod produces MyFirstMod.dll.
TIP
Use dotnet build -c Release when you want a Release build. Its output is placed in bin/Release/netstandard2.1/.
Install the test build
Copy your mod DLL into the BepInEx/plugins directory used by the game.
For a manual BepInEx installation, you can keep each mod in its own folder:
-
Mycopunk-
BepInEx-
plugins-
MyFirstMod-
MyFirstMod.dll
-
-
-
-
If you use a mod manager, open the active profile's directory and copy the DLL into that profile's BepInEx/plugins directory. Make sure you launch the game with the same profile.
WARNING
Only copy your mod's DLL. Do not copy or distribute Assembly-CSharp.dll or other game assemblies.
Check that it loaded
Close the game before replacing an existing DLL, then launch it with BepInEx enabled. After reaching the main menu, open:
BepInEx/LogOutput.logSearch for the message from Awake:
My first Mycopunk mod loaded successfully!If the message is present, the plugin built and loaded correctly. You can now start adding game code.
Troubleshooting
| Problem | What to check |
|---|---|
MycoMod or ModFlags cannot be found | Make sure the Assembly-CSharp reference in the .csproj file is uncommented and points to the current game installation. |
| The build succeeds, but the log message is missing | Check that you copied the newest DLL into the profile or game directory you launched. |
LogOutput.log is missing | BepInEx did not start. Check your BepInEx installation and make sure you launched the modded profile. |
| BepInEx reports a duplicate plugin GUID | Another copy of the plugin is installed, or the template identifiers were not changed. Remove the duplicate and give your project a unique assembly name. |
| The old log message still appears | Close the game fully, rebuild, and replace the installed DLL. |
Once the test plugin loads, continue with the publishing prerequisites when you are ready to package it.