Unity: Google Drive + Asset Bundles for D&D

One evening when I was engaged in playing D&D with my friends I realized that we had a hard time remembering the names of the characters and cities we encountered. And it would enhance our experience if we knew them and not fall back to asking our game master all the time.

 

The idea to write a small app to access a character database was born. There are already a lot of services and online tools available to do exactly this for D&D. If I were lazy I would have set up one of these services. But I thought it would be more fun and educational if I programmed the app myself. It doesn’t seem too complicated to host a few names and pictures in my cloud and build a handy client to access and modify the data. So I started to figure out the details.

 

Requirements

The requirements I came up with are:

  • mobile client for easy access
  • data hosted online to share between users
  • data must be modifiable without updating the client
  • entries contain a picture and text

I didn’t want to manage a complete database because it seemed overkill, so I went with a JSON file for the texts and an AssetBundle for the pictures. 

 

Overview of the UI screens of the App

 

Cloud Access

I dropped both on my google drive. I didn’t want to make the data publicly accessible because it contains private data from our campaign. I wanted to protect our files with a password but still be able to access them from the app. An easy solution was to set up a Google Service Account. You can manage file access for these accounts the same way as human users. They are required to log in before accessing your files. 

 

I don’t recommend using google drive as a data host if you plan to share your app with more than a few people. Google will shut down your account if there is too much traffic. I would recommend using a regular hosting service for larger user bases. It is ok for my use case because I will only use the app once a week and share it with four users.

 

Implementation

After the cloud was set up, I started implementing the Unity Client. It was straightforward to build a few UI screens to access the data and edit it. The only thing that took a while was my attempt to use Addressables for the building and loading of the picture AssetBundle. If you want to load an AssetBundle via Addressables from a non-public URL you have to implement your own AssetBundleProvider to handle the credentials. An example of an implementation is the PlayAssetDeliveryAssetBundleProvider on Github or in this unity forums thread.

 

I was able to load the bundles but it always crashed when Addressables tried to access the assets. Because it’s a fun project I kicked Addressables and used normal AssetBundles instead. Now I had to implement the loading and unloading myself. It seemed more manageable than finding out what caused Addressabls/Unity to crash without any helpful error or stack trace.

 

Not really helpful error Unity crashed with when accessing the asset bundle.

I made sure the bundle is not corrupted.

 

 

If you also want to use AssetBundles I can highly recommend the Unity Asset Bundle Browser Tool. It is officially deprecated but still works like a charm and is documented. The tool helps to manage and build AssetBundles. You can download it as a package from the Github URL in the package manager.

 

Unity Asset Bundle Browser Tool

 

Where to download packages from Github URLs