Basic

December 10 2019

7 comments

Unity Addressables CDN: Unleash Your Content Distribution

By Rubén Torres Bonet

December 10, 2019


It's Christmas time. More than ever, I feel like cutting my content update iteration times by 90%. Do this by allowing your players to download your content on-demand. Here's how you do this with Unity Addressables CDN.

Unity Addressables is a beast of a package. It helps you manage your content in Unity. Although this might sound like some tool to sort content into different directories to make it look pretty, it isn't.

Addressables is a system developed to replace the entire asset bundle workflow. It's a valuable tool for efficiently storing, loading and updating your content.

Implement it right and you'll see huge memory savings.

Give it time and you'll improve your user reviews.

Study it, and you'll iterate much faster over your game's content.

If you don't know much about Addressables, I'd suggest you start by reading my Unity Addressables Tutorial to learn the basics. This post assumes you have a basic understanding of the system.

After this post, you'll be ready to tap into the power source of Content Network Delivery. Deal?

By the way, curious about that rabbit lying on the couch? That's my rabbit Mr. Alex. He often poses like that to show off his butty.

Christmas, Anyone?

In a traditional game, we serve assets directly from the installation path. But downloading the content in run-time instead provides several advantages.

Imagine this.

Let's say you have an additive scene UI to show the current leaderboard: LeaderboardUI. You did this because showing a leaderboard gives your game the competitive edge it needs to become viral.

Experience tells you that, to keep your users engaged, you should update the game regularly. Even minor cosmetic changes help to maintain your players' interest.

So this time you are planning to update the look of your Leaderboard UI.

Christmas is approaching, so you want to put some candy here and there.

How would a typical studio approach this?

Easy. Just do the graphic changes you want. Add sprites here and there, add some animations, update some text and maybe even offer some Christmas discounts on your IAP items. Then, do a build per platform.

QA gives the green light and you upload the builds to the different stores. After the approval is given, your updated game is live on all stores.

Your users then update and enjoy some great content.

Right?

No. We were too optimistic.

This is what I skipped from the story:

  • It took your team a while to do go through the whole update process. Changes, builds, QA, uploads. Repeat. Just for a pixel-sized cosmetic change.
  • QA reported a new code bug introduced by a parallel code change. This has to be fixed first.
  • The app store delayed approving your update due to high volume of Christmas updates. Not only that, they came back to you with a security issue you have to patch first.
  • Only a tiny portion of your users updated the game on time. These OS update notifications are too easy to dismiss. Most players missed your Christmas update.

That's no good business.

What is ideal instead?

If we are after cosmetic improvements, we're mostly talking about content changes. And asset modifications do not need code changes, let alone a full new build.

Ideally, we'd like to update the content and have a way to deliver the content changes directly to the end player. We'd like to take shortcuts.

Well, it's your lucky day. Addressables lets you do this (and more).

Unity Addressables CDN: How Will It Help You?

Using a CDN will let you deliver some of your assets over the internet.

And that's great, because that means you can change them as often as you please.

This is how the Addressables-based upgraded flow will look like after upgrading our game:

  1. Make your changes to the scene. Snow, candy, love and such.
  2. Update the asset bundles withing the click of a button.
  3. Upload the new asset bundle.
  4. Your players download the updated scene as soon as they launch your game.

See what just happened there?

That's a lot of shortcuts we made. I love it. And you should too.

Alright. Today we'll learn how to set up an account on BunnyCDN. We will leverage Bunny's power to store and distribute our content.

Let's see how.

Disclaimer: if you sign up with BunnyCDN, I'll get some credit added to my account. This will help me pay the hosting services for TheGamedevGuru.

Even if you don't like bunnies, you can still apply the principles of the upcoming sections. Keep reading.

Unity Addressables CDN: Leveraging BunnyCDN

BunnyCDN is a special CDN. It will always have a special place in my heart.

BunnyCDN not only distributes your content over the networks that are the closest to your players. It also gives you the power to store your data directly within their servers.

You eliminate the complexity of hosting somewhere and serving somewhere else.

And prices are damn juicy compared to the giants. As the time of writing, storage starts at $0.01/GB per month and distribution at $0.005/GB transferred. And they give you a very generous 14-day trial with 1TB of transfer.

I'll keep the instructions shorter than the story. I promise to try.

1. Creating Bunny CDN Account

Sign up for the free trial.

Fill in the details and such, you know how that all goes. I mean, you also sign up here with your e-mail sometimes.

Once you're all set, we will create something known as storage zone.

2. Creating a CDN Storage Zone

Here we will create an area where to upload files to. Think of this as FTP server or a Dropbox account (no, I'm not affiliated with Dropbox either).

Navigate over to storage zones and add a new one. Choose a name just for you. Don't overthink it, no one else other than you will see it.

BunnyCDN - Add Storage Zone

BunnyCDN - Add Storage Zone

BunnyCDN - Storage Zone Name

BunnyCDN - Storage Zone Name

That's it. Now you've got a storage zone just for you.

Here we will upload our asset bundles. For that, we can either count on FTP or API access.

For API automation check the last section of the post. Here's how you do this with FTP.

If you go to your storage zone, you'll see a FTP section on the left menu. Clicking there will give you access to your hostname, username and password. Save these details in software like FileZilla.

BunnyCDN Storage Zone: FTP Settings

BunnyCDN Storage Zone: FTP Settings

3. Creating a CDN Pull Zone For Unity Addressables

Now that we have a storage space, we will create what is known as a pull zone.

A pull zone plays the distribution role of the equation. It takes whatever data you have in the storage zone and offers it to the world.

Unity Addressables CDN: Create Pull Zone (1)

You're still in the storage zone you just created, right?

On the top-right corner, click on Connect Pull Zone.

Now comes the interesting part: the pull zone settings.

Give it a name. This time, give your best one. This field will form part of the final URL. You want it to look pretty.

When it comes to performance/price, you have two options. You can select the Standard Tier, which is more expensive but includes a lot of nodes around the world.  This option is great if you absolutely want to minimize latency. And you want to do that for your website like I do, for instance.

My recommendation for you? Save some money and go for the High Volume Tier instead. You'll benefit more from an extra coffee per month than by saving your clients 20ms in downloading asset bundles. This tier will costs you half.

Unity Addressables CDN: Create Pull Zone (2)

Unity Addressables CDN: Create Pull Zone (2)

Once you created it, look for the HTTP URL to access your content. You can find it in the pull area you just created. It follows the following structure:

http://your-pullzone-name.b-cdn.net
(e.g. http://crappycrush.b-cdn.net)

Okay, copy that URL into your clipboard. We will need it now.

4. Configuring Unity Addressable Profiles

Unity uses the concepts of Profiles to set the "environment variables" for the Addressables system.

RemoteLoadPath is the important variable. This field tells Unity the base URL to use to look for the remote assets we will build.

Open your profiles by clicking on Window Asset Management Addressables Profiles. Then, select your current profile (or create a new profile called Production). Change the RemoteLoadPath to reflect your custom CDN URL and keep the [BuildTarget] suffix.

Since asset bundles are platform-dependent, Unity will replace the BuildTarget platform on run-time. Here's an example:

http://crappycrush.b-cdn.net/[BuildTarget]

Now Unity knows where to find our remote assets. The next step is to configure which assets should be built for remote distribution.

Unity Addressables CDN: Profiles

Unity Addressables CDN: Profiles

5. Configuring Unity Addressable Groups

I assume you have some Addressables-based content. In my case, it is a scene called LeaderboardUI. This scene is within the Leaderboard group.

Note that, making a scene Addressable will automatically resolve the scene's asset dependencies for you. The final asset bundles will contain all the content the scene requires.

Navigate to the Addressables Groups window. Find it under Window → Asset Management → Addressables → Groups. Then, select the group you want to distribute remotely.

By selecting the group, the inspector will show you its settings. There, you'll want to change the build path from LocalBuildPath to RemoteBuildPath. Change as well the load path from LocalLoadPath to RemoteLoadPath. This will make sure Unity knows we are marking this asset bundle for remote distribution.

To test your CDN I suggest you to temporarily turn off the asset bundle caching system.

Unity Addressables CDN: Group Settings

Unity Addressables CDN: Group Settings

Back to the Addressables Groups, make sure the current profile is set to the profile we just modified.

Now we just need to build the remote asset bundles. We do this by pressing Build → New build → Default Build Script. You'll find the generated bundles under YourUnityProject/ServerData.

6. Uploading Addressables Asset Bundles to CDN

If you navigate to the ServerData directory, you'll find a subfolder named after the active build target. As I am targeting windows, I have a subdirectory called Standalone64. Inside that directory you'll see all asset bundles built for that specific target.

But in any case, you'll want to upload the contents of the ServerData directory. You can do this with the FTP connection to your storage zone.

Unity Addressables: CDN Root Content

Unity Addressables: CDN Root Content

7. Testing Your Remote Addressables Content

This is the easiest step. Do you know why?

Because if you already had Addressables in place, there's no change required in your code. Your new clients will now fetch your bundle from the server automatically.

Addressables CDN: Remote Load Test

Addressables CDN: Remote Load Test

So go ahead, build a player and test your game. You should see in the server logs that your CDN served your game the content it demanded.

Automating Your Addressable CDN Uploads

This was great.

We took shortcuts. We managed to cut our content update iteration times by 75%.

But can we reach 90%?

As you see, we're still bottlenecked on uploading the assets through FTP. And this can be time-consuming when repeated multiple times.

That's why I prepared a Unity integration that lets you upload your bundles within the editor.

Build your asset bundles: 1 click.

Upload your asset bundles: 1 click.

Get your free CDN upload extension and the Unity project for this post clicking here.

On top of that, you'll get an exclusive picture of Alex signed by himself.

And always keep playing.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Rubén Torres Bonet

    About the author

    Born Game Developer, now ready to help you develop better games. Primary programmer on Star Trek Bridge Crew (Oculus Quest), Diamond Dash. Programmer on Time Stall, Catan Universe, Anne Frank House VR, Jelly Splash, Blackguards Definitive Edition. I also worked in minor XR experiences for HoloLens and Vive for clients such as Audi and Volkswagen.

    You might also like

    >