Importing the hands into the game

Updated a year ago

Creating the asset bundle

With our hand prefabs done, it's time to create an asset bundle using the Asset Bundle Browser. You can also use ThunderKit's asset bundle system if preferred. Navigate to Window > AssetBundle Browser. With the browser open, right click in the browser and select "Add new bundle" and give it a name. Then, drag all your hand prefabs into your bundle. You will see that everything else that's needed also get added automatically.

You're now ready to build your asset bundle. In the browser, switch to the "Build" tab and press the "Build" button. After a little while, your asset bundle will be created in your project folder. With an explorer, go to your project folder and navigate to AssetBundles > StandaloneWindows. You will see your asset bundle as well as its manifest file.

Loading the asset bundle into your mod

If it isn't already done, prepare a mod solution with Visual Studio. If you don't have modding experience for Risk of Rain 2, I recommend reading the first mod tutorial to get familiar with how it works. If you already have a mod for your custom character, you can use that as well.

You now need to import the bundle as a resource. To do that, right click on the project and go to properties. In the "Resources" tab, you can create a resources file by clicking the blue prompt.

Once you have a resources file, you can click Add Resource > Add existing file... and find your asset bundle in your Unity project folder. Make sure the file type is set to "All files". Once it is imported, build your solution with Build > Build solution or Ctrl+Shift+B.

Adding your hand prefabs with the VR API

In order to interact with the VR mod, you need the VR API. To add the API as a dependency, add the following line above your mod class: [BepInDependency("com.DrBibop.VRAPI")].

You can then add the VRAPI.dll file in your project dependencies. You can easily access this file by downloading the mod manually and extract it. In the explorer, right click "Dependencies" and click "Add Project Reference..." which will allow you to browse for the VRAPI.dll file. You also need to import Unity's Asset Bundle Module which is located in your game's Managed folder.

With your dependencies now ready, let's make sure the VR mod and motion controls are enabled for the user before loading the bundle and our prefabs.

using BepInEx;
using UnityEngine;
using VRAPI;

namespace CustomVRCharacter
{
    [BepInPlugin("com.DrBibop.CustomVRCharacter", "CustomVRCharacter", "1.0.0")]
    [BepInDependency("com.DrBibop.VRAPI")]
    public class CustomVRCharacter : BaseUnityPlugin
    {
        private void Awake()
        {
            RoR2.RoR2Application.onLoad += LoadCustomHands;
        }

        private void LoadCustomHands()
        {
            //If the VR mod is installed and has motion controls enabled
            if (VR.enabled && MotionControls.enabled)
            {
                //Load the asset bundle
                AssetBundle assetBundle = AssetBundle.LoadFromMemory(Properties.Resources.mybundle);

                if (assetBundle)
                {
                    //Load the hand prefab
                    GameObject handPrefab = assetBundle.LoadAsset<GameObject>("MyCustomHand");

                    if (handPrefab)
                    {
                        //Add the prefab as a custom hand
                        MotionControls.AddHandPrefab(handPrefab);
                    }
                }
            }
        }
    }
}

You are now ready to build and try the mod for yourself! If you need to make some changes in Unity, simply rebuild the bundle, delete the one in your Resources folder and drag the new one in.

Next step: Using the VR API