# How to create an AssetBundle

Let's get started with the requirements! \
For this tutorial you will need the same requirements as the first tutorial.

**1)** First, create a new Unity project with the same version as the one required in [**How to create a mod project**](https://docs.greenhellmodding.com/modding-tutorials/how-to-create-a-mod-project).

**2)** Then once the first step is done, download [this file](https://www.raftmodding.com/TeKGameRMods/AssetBundleBuilderByTeK.zip) and place it into your Unity Project as shown below. This will allow you to build your asset bundle file. &#x20;

<div align="left"><img src="https://1233583207-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5KKfkIqMO_EFPortVm%2F-M5jGTldSf4KpH8soL9S%2F-M5jGn6AxKD9spuzVtQW%2Fimage.png?alt=media&#x26;token=468f315d-6ef8-4050-a99b-26c0164680cb" alt=""></div>

**3)** Add your stuff to the asset bundle as shown below. &#x20;

![](https://1233583207-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5KKfkIqMO_EFPortVm%2F-M5jGTldSf4KpH8soL9S%2F-M5jGqfSMvjFkLxtHrD6%2Fimage.png?alt=media\&token=8b380f9b-929a-4bd5-8e27-5b0a81bd7971)

**4)** Once you have everything in your assetbundle, build it by right clicking anywhere and clicking on **Build AssetBundles** as shown below. &#x20;

<div align="left"><img src="https://1233583207-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5KKfkIqMO_EFPortVm%2F-M5jGTldSf4KpH8soL9S%2F-M5jGtRxnif7PyECN-xZ%2Fimage.png?alt=media&#x26;token=313b1402-e89e-4525-ac68-48c7a85fc854" alt=""></div>

**5)** If your assetbundle has succeeded building you should be able to find it in **Assets/AssetBundles**; Once you found it, copy it into your mod project folder where your .cs files and your modinfo.json file are located as shown below. &#x20;

<div align="left"><img src="https://1233583207-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5KKfkIqMO_EFPortVm%2F-M5jGTldSf4KpH8soL9S%2F-M5jHBoAkHlMElnkvpEb%2Fimage.png?alt=media&#x26;token=2c381e99-7d31-4ac5-8c17-e183c87fce0a" alt=""></div>

**6)** Now let's load it into the game using our previous mod made in the [**How to create a mod project**](https://docs.greenhellmodding.com/modding-tutorials/how-to-create-a-mod-project) tutorial. Open your mod project and change your start method type from **`void`** to **`IEnumerator`** and copy the code below into the start method as shown below; You will also need to create a new variable in your mod to be able to access the asset bundle from anywhere in your mod.

{% tabs %}
{% tab title="Help Image" %}
![](https://1233583207-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5KKfkIqMO_EFPortVm%2F-M5jGTldSf4KpH8soL9S%2F-M5jHm-2JfRQ2XrbPOyW%2Fimage.png?alt=media\&token=5e437d19-8268-47c6-9c75-fc0a9e1fde7e)

{% hint style="info" %}
I&#x66;**`IEnumerator`** is underlined in red, simply add **`using System.Collections;`**&#x61;t the top of your mod file.
{% endhint %}
{% endtab %}

{% tab title="Code" %}

```csharp
AssetBundle asset;

public IEnumerator Start()
{
    AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(GetEmbeddedFileBytes("tutorial.assets"));
    yield return request;
    asset = request.assetBundle;

}
```

{% endtab %}
{% endtabs %}

**7)** Loading an asset bundle is good, but we also need to unload it when we unload our mod. So, to do that in your ***`OnModUnload`*** method simply add **`asset.Unload(true);`** as shown below. &#x20;

<div align="left"><img src="https://1233583207-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5KKfkIqMO_EFPortVm%2F-M5jGTldSf4KpH8soL9S%2F-M5jI38w3Ky0YxQQdwSW%2Fimage.png?alt=media&#x26;token=534cfa39-4efc-4558-843b-bdb6cc9b273b" alt=""></div>

**8)** Now, to load something from our asset bundle simply use **`asset.LoadAsset<T>("assetname")`** for example to load the ***RedCube*** that i added into the example asset bundle earlier i can just do **`asset.LoadAsset<GameObject>("RedCube")`**.

And here is it! As this can be a bit complicated if you encounter any issue or if you are blocked at a specific step, feel free to join our [Modding Discord](https://www.greenhellmodding.com/discord) and ask for help in #support.
