# Making Asset bundles

### Difficulty: 5/10 <img src="https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-MfzOs8r_UzTe7WhP3Tc%2F-MfzUfwEbw3CPleihZ-O%2Fdifficulty_5.png?alt=media&#x26;token=cfc8004f-5949-4878-a25f-51aa18c02091" alt="" data-size="original">&#x20;

Making asset bundles are a way to use real prefabs in gungeon.&#x20;

## Creating Asset Bundles

You need to download unity and download version 2017.4.40 so that the asset bundles you make are compatible with gungeon. <br>

They can be located here:

{% embed url="<https://unity3d.com/get-unity/download/archive>" %}

Create a new folder called Editor:<br>

![](https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-Mfzg3jzgcrJ1crw9We0%2F-MfzjreoszBr_uzslFct%2Fimage.png?alt=media\&token=06027ca5-b95b-4196-b49c-54392026790c)

And inside the floder create a c# script and call It CreateAssetBundles.\
To do this right click and select create>C# script

![](https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-Mfzg3jzgcrJ1crw9We0%2F-Mfzk9AG-JlzynJrfAZP%2Fimage.png?alt=media\&token=b82edf97-59ae-4ecc-a5fe-6b61d098d74e)

![](https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-Mfzg3jzgcrJ1crw9We0%2F-MfzkEA1TjQJz_xpRlNp%2Fimage.png?alt=media\&token=435b5059-596f-48df-a46f-4a91348ac920)

Now open the script and paste this code in:

```csharp
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;

public class CreateAssetBundles
{
    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles()
    {
        string assetBundleDirectory = "Assets/StreamingAssets";
        if (!Directory.Exists(Application.streamingAssetsPath))
        {
            Directory.CreateDirectory(assetBundleDirectory);
        }
        BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
    }
}
```

Go back to the assets folder and create a new folder called BundledAssets, this will contain all the gameobjects, textures, etc.\
\
select the object you want to be part of the asset bundle and go to the bottom of the inspector panel

create a new assetbundle

![](https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-Mfzg3jzgcrJ1crw9We0%2F-MfzlFDByHRw2TYOamR3%2Fimage.png?alt=media\&token=e8a77fce-22f5-495d-ba4e-275b15ab37b5)

![](https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-Mfzg3jzgcrJ1crw9We0%2F-MfzlAzs9r_gtzNPm7Ha%2Fimage.png?alt=media\&token=2fbd2722-207f-49bc-8e45-9bc6bfb1861d)

and then any object you want in the assetbundle will go under the one you made.

click the assets tab at the top left and go to the bottom where it says build assetbundles.

## Loading the AssetBundle&#x20;

in your mod drop this file in.

{% file src="<https://1229800202-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQAkTlyeVttU3CJdmYk%2F-Mfzg3jzgcrJ1crw9We0%2F-Mfzln80wUV3sUl_lXLj%2FAssetBundleLoader.cs?alt=media&token=2d82fd71-2b77-4acd-ad0f-642965a69d03>" %}

in your module add\
`public static AssetBundle ModAssets;`

before you load anything from this asset bundle do \
`ModAssets = AssetBundleLoader.LoadAssetBundleFromLiterallyAnywhere("assetbundlename");`&#x20;

## Loading objects from the AssetBundle

to load an object use \
`ModAssets.LoadAsset<ObjectType>("object name");`

for example, if it's a gameObject use

`ModAssets.LoadAsset<GameObject>("object name");`
