Setting Up Mod Development Environment - Valheim-Modding/Wiki GitHub Wiki
Setting Up A Mod Development Environment
Depending on what mod you are wanting to create there will be different steps to the setup process. First identify your situation:
- I want to ONLY tweak existing behavior or code.
- I want to make tweaks but allow the users to select values (configurations).
- I want to add custom content like creatures, items, or locations.
- I am unsure! Start small and follow situation 1 steps.
All mods will require a similar basic setup.
Links to common packages and libraries mentioned in this article can be found on this page!
It is highly recommended to read this guide fully before completing any steps. If you need assistance from any of the modding communities different authors will be able to help best with different technologies.
Development Environment Checklist
Use this checklist as you go!
Situation 1:
- Basic Setup - IDE
- Basic Setup - Dependencies
- View Vanilla Code
- Access Private Fields and Methods
- View Game Assets (with the Unity Explorer tool)
Situation 2:
- Select a Template and Libraries
- Complete steps for your other situations
Situation 3:
- Select a Template and Libraries
- Basic Setup - IDE
- Basic Setup - Dependencies
- View Vanilla Code
- View Game Assets (game rip)
Basic Setup
Step 1: Select a Template and Libraries
These choices will influence your setup for the rest of the Basic Setup section.
(Situation 2) Configuration Syncing
If you are making a mod that has client side configuration, or no configuration options only then you do not need to worry about syncing and can skip this step.
If you want to create a mod that allows the user to configure options on a server there are two existing solutions. These libraries both support syncing configuration values. If you do not use one then players will be able to change configurations however they please. See Best Practices for more information.
- Jotunn
- ServerSync
(Situation 3) Custom Content Injection
If you want to create a mod that injects custom content (assets) to the game (Creatures, Items, Locations, etc) this can be done easily with an existing library:
- Jotunn
- The "Managers"
(Situation 2 & 3) Templates
Based off your previous choices there are modding templates available to make setup quick and easy. If you do not need any of these packages continue on to the next step. Using these templates and included setup guides may have you complete steps also included in this guide. Skip any you have completed going forward.
Step 2: Integrated Development Environment (IDE)
You will need to compile a dynamical-linked library (.dll) regardless of your project direction. This is the file that will contain your mod to load into the game. This is done typically via a code editor. The community recommends one of the following:
You will need the following development package. Your installer may give you the option to add these during the setup process. If not you will need to add this manually:
Step 3: Dependencies
Next you will need BepInEx. The community maintains a pack for Valheim. It is highly recommended to use this pack, using the latest version of BepInEx can cause issues for other mods. The pack includes HarmonyX, the tool used by the community to make patches and inject code changes into the game.
Manually download this pack. See Best Practices for more information on best installation location. The Creating Your First Mod Tutorial explains how to add a reference to this package if you need more guidance.
(Situation 1 & 3) View Vanilla Code
If you need to view the vanilla code to make changes or understand how things work you will need a more detailed decompiler. There are two standalone options you can download and manually install:
Viewing the decompiled game assemblies can tell you what classes, fields, and methods are available. However, this will not always give you the information you need. For example: A Creature's maximum health, swim speed for specific Fish, or Piece category values for the build hammer. To see what scripts are used and the values set on each asset you will need to complete the "View Game Assets" step below.
(Situation 1) Access Private Fields and Methods
Now that you can view the code you can see Access Modifiers. If you need to access private or protected fields or methods in your mod you can publicize your assemblies to make it easier. See Best Practices for more information.
(Situation 3) View Game Assets
Game Assets can be viewed in-game with the Unity Explorer. Install this as you would any mod. This can be very useful for fast debugging and testing for your mod.
A reference unity project called a "game rip" can be used to view assets outside of the game. If you are making your own assets based on vanilla, or editing vanilla assets, this is how you can get an exportable copy for your own project. This step can also be useful if you are editing existing code and get confused or lost. This can take up to a few hours, so make sure you have plenty of time to complete this step!
If you just need to check a few things for development the unity explorer tool may be the best choice rather than a full game rip.
What exactly can you see with a game rip?
- GameObjects and other Prefabs and their names
- MonoBehavior scripts and values on each GameObject
- Audio Files
- Sprites
- etc...