A collection of Project and Item templates to speed up the process of creating Unity game mods using the BepInEx patcher and plugin framework.
I have created a full video guide to downloading, installing, and using the templates. You can find that and more mod related videos on my Daft Apple Games YouTube channel.
The template pack comes with the following:
The project template contains a suggested folder structure, references and boilerplate starter classes for a new BepInEx based Unity mod.
Four item templates are included that provide boiler plate code for a number of core mod class types, that you might want to add to your project.
This contains a suggested structure for a "plugin" class for use with the BepInEx framework.
This contains a suggested structure for a "monobehaviour" class, for introducing new components and behaviours.
This contains a suggested structure for a static "utils" class, for creating static helper methods.
This contains a suggested structure for a "patch" class, for building Harmony patch classes and methods.
The template pack comes as a single ZIP file and the latest version for you to use can be found here under Releases.
To install the latest release:
-
Unzip the download file to a location on your machine.
-
You should have a folder structure as follows:
-
In Windows Explorer, navigate to this location. Note that the physical location of "Documents" may change depending on a number of factors, including whether or not you have OneDrive installed:
Documents\Visual Studio 2022\
-
Copy the unzipped Templates folder into the Visual Studio 2022 folder on top of the existing Templates folder. This will add the appropriate ZIP files to the Visual Studio template folder.
-
Restart Visual Studio.
The templates should now be available for use.
Once you've installed the templates, you can create a new project using the Project template.
- Create a new project by selecting the "Unity Mod (BepInEx)" project template.
- Enter a name for the new project. This name will be used in both the default plugin class and in the default namespace for the project.
- Click create.
- The project structure will be created with boilerplate code class files in place for your to amend.
There are a number of things you must now change to suit your needs. It is VERY IMPORTANT that you do this, or your mod will not compile or deploy properly, and may behave in ways you do not expect.
You need to review and amend the following:
You will need to modify the following references to point to your installed game location:
- 0Harmony
- Assembly-CSharp
- BepInEx
- UnityEngine
Review and edit the post-build scripts to include the path to your target game BepInEx plugin folder.
Review and edit the boilerplate code to your needs. Review, remove, or update the following:
- Plugin.cs
- Patches\PlayerPatches.cs
- MonoBehaviours\Component.cs
- Utils\ModUtils.cs
If you download and apply an update to the templates, you may have to run this process to make the updated templates available in Visual Studio:
-
From the Start menu, open Visual Studio 2022, right click Developer Command Prompt for VS2022 and select More > Run as administrator:
-
Enter and execute the following command:
devenv /installvstemplates devenv /updateconfiguration
-
Restart Visual Studio.
The updated templates should now be available for use.
All source is available in the Templates folder. To build and deploy changes to the templates, you can use the included batch files.
-
Amend
config.bat
and set the path to 7-zip, Visual Studio Documents folder and the Visual Studio IDE folder. You need to set all of these parameters correctly. Do not include double quotes and do not include trailing slash characters on folder paths. For example:set zip=C:\Program Files\7-Zip\7z.exe set vsdocs=C:\Users\MyUser\Documents\Visual Studio 2022 set vsbin=C:\Program Files\Microsoft Visual Studio\VS2022\Community\Common7\IDE
-
Run
build.bat
to build a new release ZIP in the Releases folder. -
Run
build.bat Y
to build and deploy to your local Visual Studio installation.
A ZIP file for release and deployment can be found in the Releases folder, postfixed with the build date and time.