> For the complete documentation index, see [llms.txt](https://foreign-gnomes.gitbook.io/everhood2-modding/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://foreign-gnomes.gitbook.io/everhood2-modding/basics/custom-coding.md).

# Custom coding

It is possible to have custom scripts inside your mod. For that, you will need to setup a new DLL and tied to Everhood 2 and Unity.

### Setting up a new code DLL

{% stepper %}
{% step %}

### Open Visual Studio > Create a new project > Class Library

{% endstep %}

{% step %}

### Give the project any name, the name of the project will be the name of the DLL. 3.&#x20;

{% endstep %}

{% step %}

### Set the project framework to '.NET Standard 2.1'.

{% endstep %}

{% step %}

### After the project loads go to Project > Add Project reference... > Browse...&#x20;

Use CTRL+A to select all DLLs under '.\Everhood2\Everhood 2 Data\Managed'&#x20;

and use CTRL+\[Left Click] to deselect 'netstandard.dll' and any DLLs starting with 'System'.

{% endstep %}

{% step %}

### Create any scripts you want to use in the custom world.

You'll have access to all of Unity's features and can create a script that can be dragged into the inspector by having it inherit from MonoBehaviour.&#x20;

You can also access classes from Everhood 2 that you can explore and analyze using dnSpy and sinai-dev/UnityExplorer.
{% endstep %}
{% endstepper %}

### Using the DLL in Unity

{% stepper %}
{% step %}

### Build the project by going to Visual Studio > Build > Build Solution

{% endstep %}

{% step %}

### You'll find your exported dlls in '\[Visual Studio project]\bin\Debug\netstandard2.1'.

From there find the dll that matches your project name and place it somewhere in your Everhood 2 Unity mod folder.
{% endstep %}

{% step %}

### In Unity disable Auto Reference and Validate References in the settings of your DLL

{% endstep %}
{% endstepper %}

### Updating the DLL in Unity

To update the dll build the project and replace the dll using file explorer, Unity will do the rest.

***

### Storing references of game scripts

{% hint style="danger" %}
While you can access game scripts within methods, parameters, attributes etc. \
\
You specifically cannot store the reference of  game scripts within a class as Unity will then attempt to serialize them even if you mark them as `[NonSerializable]`which will break the DLL.&#x20;
{% endhint %}

This will not work:\
![](https://3981649557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTwQLuEF98ZWbkct6sTun%2Fuploads%2FMelR5e6Jj2i7wgQMp4eV%2Fimage.png?alt=media\&token=2a10a81c-2f1f-46aa-9c04-c3245ecfa3c8)

The workaround is to store the reference as "object" like this and then Cast it back to the target class:

![](https://3981649557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTwQLuEF98ZWbkct6sTun%2Fuploads%2FmGUAJ0Z7DfOI6JL89gV6%2Fimage.png?alt=media\&token=0a3ddffd-3079-444e-a350-731011504e88)\
\
Then Cast, an efficient method could be for example:

<div align="left"><figure><img src="https://3981649557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTwQLuEF98ZWbkct6sTun%2Fuploads%2FgnpmHTBKz4ryv9Pv17Q4%2Fimage.png?alt=media&amp;token=2a3db707-e67b-45e5-a127-359729b60382" alt=""><figcaption></figcaption></figure></div>
