Valheim Unity Project Guide - Valheim-Modding/Wiki Wiki

Original URL: https://github.com/Valheim-Modding/Wiki/wiki/Valheim-Unity-Project-Guide

This is NOT a guide for modding, but a guide for getting started on custom AssetCreation for modding

CREDITS: @BlueAmulet for teaching me how to do this. @Charlotte for helping me as well! @GeranisaurusRex for getting me to make the guide.
Valheim Modding Discord: https://discord.gg/z6urRQ9XBY

Programs needed:

uTinyRipper: https://sourceforge.net/projects/utinyripper/files/latest/download
ILSpy Preview 3: https://github.com/icsharpcode/ILSpy/releases/latest
Unity Hub: https://unity3d.com/get-unity/download
Unity 2019.4.24f1: https://unity3d.com/unity/whats-new/2019.4.24
BepInExPack Valheim: https://valheim.thunderstore.io/package/denikson/BepInExPack_Valheim/
Steamworks API: https://github.com/rlabrecque/Steamworks.NET/releases

Download uTinyRipper_x64.zip and ILSpy_binaries_(version).zip. Extract both of these to their own folders.
Click the "Download Unity Hub" to get UnityHubSetup.exe.
Click on "Manual Download" to get denikson-BepInExPack_Valheim-(version).zip
Download Steamworks.NET_(version).unitypackage

You should have the following files and folders:
required_files
Install Unity Hub first, then go to the Unity 2019.4.24f1 page and click the "Install this version with Unity Hub." link.

When installing the Unity Editor through Unity Hub, no Build Support modules are needed and they can all be unchecked.

Instructions:

Open uTinyRipper.exe and drag the Valheim Folder from Steam into it and export to your desired folder. uTinyRipper will create a new folder called "valheim" in the folder you chose, containing a new Unity project.

Open ILSpy.exe and set it to "C# 7.3 / VS 2017.7".
ilspy_settings
Select all Assemblies in the list if any, right click, and click Remove. Go to Valheim's Managed folder, and drag all the dlls starting with assembly_ into ILSpy's Assemblies list.
Go to "denikson-BepInExPack_Valheim\BepInExPack_Valheim\unstripped_corlib" and drag "mscorlib.dll" to the Assemblies list.
Select all assemblies starting with "assembly_", right click and click "Save Code". Save the "Solution.sln" to your "valheim\Assets\Scripts" folder. ILSpy will complain the target folder is not empty and that files will be overwritten, this is exactly what we want, so click Yes.
ilspy_overwrite

Now in Windows Explorer, go to the "valheim\Assets\Scripts" folder, and delete the "Solution.sln" file. Type ".1.cs" into the search bar and delete each result. For each assembly_ folder, go in and delete the "Properties" folder.
explorer_search

Open Unity Hub, click "Add", and select the "valheim" folder. Set the project's Unity Version to "2019.4.24f1", and open the project.
unity_hub
It will ask if you want to upgrade the Project, click "Confirm". Unity will take a while as it processes all the assets. If Unity says an API Update is Required, click "I Made a Backup. Go Ahead!"

After all this you should have a working Unity Project for valheim.
There will be several errors about Shaders and render passes, this is normal, and will be addressed under "Additional steps"

Additional steps:

Shaders

uTinyRipper does not handle shaders properly and will lead to several shader related errors, and invisible/pink objects.
There are some additional steps we should take to make the Unity project more usable.
Go to Edit -> Project Settings -> Graphics, find "Built-in Shader Settings" and set Deferred to "Built-in shader".
unity_deferred
Go to Assets\Materials, select every material, and set the shader to "Standard" in the Inspector. This will make it so everything will be visible and textured.
unity_materials

Preventing scripts from running outside of runtime

In your Scripts folder, search for Heightmap.cs, open that and remove the [ExecuteInEditMode] annotation from the class. This prevents an infinite loop from occurring and permanently freezing the editor when you open a scene that has the behaviour enabled.

Fixing Utils.cs

The Utils class throws an error upon loading Unity. To fix it, search for Utils.cs in your Scripts folder, open the file and go to the line with the ambiguous reference (Unitys Console shows the exact line of error). Change CompressionLevel.Fastest to System.IO.Compression.CompressionLevel.Fastest and save the file.

Steamworks

With your unity project open, double click on the Steamworks.NET .unitypackage file and wait for it to load but don't import yet otherwise you will get duplicate code.

  1. Uncheck the Assets folder. This unchecks everything underneath it.
  2. Check the Assets/Plugins/x86 and Assets/Plugins/x86_64 folders.
  3. Click import

import_steamworks