Comment on page
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.
3) Add your stuff to the asset bundle as shown below.
4) Once you have everything in your assetbundle, build it by right clicking anywhere and clicking on Build AssetBundles as shown below.
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.
6) Now let's load it into the game using our previous mod made in the How to create a mod project tutorial. Open your mod project and change your start method type from
IEnumeratorand 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.
IEnumeratoris underlined in red, simply add
using System.Collections;at the top of your mod file.
public IEnumerator Start()
AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(GetEmbeddedFileBytes("tutorial.assets"));
yield return request;
asset = request.assetBundle;
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
OnModUnloadmethod simply add
asset.Unload(true);as shown below.
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.
If you done everything correctly your asset should now be in the game. For example my red cube spawned in the mainmenu