Creating and Using AssetBundles - SuperKael/Gadget-Core GitHub Wiki

One of the main things you can do with a Roguelands Unity Project is create AssetBundles. AssetBundles are a collection of one or more assets stored in a file, that can be loaded by a Unity game at run-time. In terms of Roguelands modding, this means you can create things like new enemies and such in the Unity editor, export them to a file, and then load them with your mod. That being said, unfortunately, the Unity Editor UI doesn't provide a way to create asset bundles - you need an editor script to do it. The following steps describe how to set up this editor script, export the AssetBundle(s), and then load them with your mod using Gadget Core.

Requirements/Prequesites: A Roguelands Unity Project as created in the guide "Creating a Roguelands Unity Project", AssetBundleCreator.cs, and GadgetCore v1.1.3 or later installed in your Roguelands game, and referenced in your mod.

  1. First, in your Roguelands Unity Project, create a folder named "Editor" inside the "Assets" folder, and drop the AssetBundleCreator.cs file into there.
  2. Upon doing so, you can now select on the menu bar at the top of the Unity Editor window 'Assets' -> 'Build Asset Bundles'. Do not actually select this yet, just verify the option appears.
  3. Go through the Assets folder and its subdirectories, and select all of the assets that you want to include in your AssetBundle. For each one, once selected, look at the very bottom of the Inspector panel, and select the dropdown to the right of where it says "AssetBundle". For the first asset you add, select 'New...' and then enter the name of your AssetBundle. For all later ones, just select the name of your bundle from the dropdown.
  4. Once all of your desired assets have been added to the bundle, now select 'Assets' -> 'Build Asset Bundles'. After a few seconds, this will create a folder inside your project folder named "AssetBundles". There will be a few files there, but the one(s) you are interested in are the one(s) that match the name(s) of the bundle(s) you specified earlier, and do not end in '.manifest'. The bundles have no file extension - normally, you would want them to end with '.assets', but in this case I have intentionally made it so that they will not. This is because if they have the '.assets' extension, UMF will try and fail to load them, and always crash the game when loading your mod.

Alright, so now your Asset Bundle(s) have been created - now you just need to actually be able to load them into the game.

  1. Place the Asset Bundle(s) inside of the Assets/ModName/ folder inside your mod - just like you would textures or audio clips.
  2. To load these into the game, call GadgetCoreAPI.LoadAssetBundle(string file). Pass the name of your AssetBundle file to this method, and it will return an AssetBundle reference. To load assets from the AssetBundle, use AssetBundle.LoadAsset. Note that this uses essentially the same syntax as Resources.Load, although it requires fully-qualified asset paths. So, if you have an asset in the AssetBundle at the path 'Assets/Resources/e/customenemy', then you have to pass "Resources/e/customenemy" to AssetBundle.LoadAsset.

And you're done! Now you can create and load AssetBundles in your mod!