> For the complete documentation index, see [llms.txt](https://api.raftmodding.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.raftmodding.com/modding-tutorials/how-to-create-an-assetbundle.md).

# How to create an AssetBundle

This tutorial is designed to demonstrate how to import assets into the game, including 3D models, textures, prefabs, particles, and more.

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://api.raftmodding.com/modding-tutorials/how-to-create-a-mod-project).

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

<div align="left"><img src="https://352575278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LmZ48Gg-hWqQWenxAnx%2Fuploads%2FQeLEbeJVaJAX9GPUlRc4%2Fb2.png?alt=media&amp;token=c32f61c8-717e-4384-b72e-8e55e2bef815" alt=""></div>

**3)** Add your stuff to the asset bundle as shown below.

<div align="left"><img src="https://352575278-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmZ48Gg-hWqQWenxAnx%2F-LtLJG7ZUEiHfsT2hp0C%2F-LtLJKtPTOlOppgOmMjh%2Foof.gif?alt=media&amp;token=5a766b56-25f8-4c11-840c-25a52cd5bb33" alt=""></div>

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

<div align="left"><img src="https://352575278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LmZ48Gg-hWqQWenxAnx%2Fuploads%2Fjmd7Mz4sxasHI7BdpDbl%2Fbundle.png?alt=media&amp;token=79ce3641-f60e-4d7c-bf65-6c2f355715ce" 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.

![](https://352575278-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmZ48Gg-hWqQWenxAnx%2F-MDQ-adr57lbavMb7RxO%2F-MDQ1C_RcxU6siSuHhEY%2Fimage.png?alt=media\&token=69dc2cef-6189-42dd-adb3-a8e279a0ffbd)

**6)** Now let's load it into the game using our previous mod made in the [**How to create a mod project** ](https://github.com/TeKGameR950/RaftModdingDocs/blob/master/modding-tutorials/broken-reference/README.md)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://352575278-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmZ48Gg-hWqQWenxAnx%2F-MDQ-adr57lbavMb7RxO%2F-MDQ1SRq18oZy4b7ObdY%2Fimage.png?alt=media\&token=48938a90-2eba-47cc-8159-688950db517c)

{% hint style="info" %}
If\*\*`IEnumerator`\*\* is underlined in red, simply add \*\*`using System.Collections;`\*\*at 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.

![](https://352575278-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmZ48Gg-hWqQWenxAnx%2F-MDQ1bq1wsMlItIub0Q3%2F-MDQ1fIrpEeiqVmrUZU3%2Fimage.png?alt=media\&token=44bb377d-fe42-4dc9-9fce-3fd60f705536)

**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")`** as shown below.

<div align="left"><img src="https://352575278-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmZ48Gg-hWqQWenxAnx%2F-LtLNGZMNiWPaXInkUek%2F-LtLSQJQVv7eyz5jZn7L%2F7.PNG?alt=media&amp;token=aeb75169-953e-4f91-81c8-b383ef9c4fd3" alt=""></div>

If you done everything correctly your asset should now be in the game. For example my red cube spawned in the mainmenu :smiley:

<img src="https://352575278-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmZ48Gg-hWqQWenxAnx%2F-LtLNGZMNiWPaXInkUek%2F-LtLSxA1QKuB0Rmg-ie9%2F8.PNG?alt=media&amp;token=1e596e74-d4cb-45d0-8202-738953aa183c" alt="" data-size="original">

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.raftmodding.com/discord) and ask for help in [#support](https://discordapp.com/channels/451507895075471383/636994378618896436).
