Guide for Unity Addressable Asset System.
Check out this sample code repo.
This guide supports languages below.
Created: 2020-07-03
Last updated: 2020-08-26 minor typo correction
To be simple, we would not create any models.
Create a project with Universal Render Pipeline
template to use sample models.
Select Windows > Package Manager
.
Search Addressables & install it.
Select Windows > Asset Management > Addressables > Groups
.
Click Create Addressables Settings
.
We would categorize assets into Materials, Models, Prefabs, Shaders, Textures like Assets\ExampleAssets
folder.
To do this, select Create > Group > Packed Assets
on Addressable Groups window and rename it.
From Assets\ExampleAssets
folder, move assets into proper group on Addressable Groups window.
To shorten the name choose assets, right-click and select Simplify Addressable Names
.
Select Tools > Labels
.
Create labels according to groups we produced at previous step.
Add proper label to each Addressables.
Remove Workshop Set & Props under Example Assets
GameObject from the scene.
Add following 2 classes.
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
public static class AddressablesLoader
{
public static async Task InitAssets<T>(string label, List<T> createdObjs, Transform parent)
where T : Object
{
var locations = await Addressables.LoadResourceLocationsAsync(label).Task;
foreach (var location in locations)
{
createdObjs.Add(await Addressables.InstantiateAsync(location, parent).Task as T);
}
}
}
Make sure that this monobehaviour script should be attached to any of GameObjects.
We already have Example Assets
GameObject, so let's use this.
using System.Collections.Generic;
using UnityEngine;
public class AddressablesController : MonoBehaviour
{
[SerializeField]
private string _label;
private Transform _parent;
private List<GameObject> _createdObjs { get; } = new List<GameObject>();
private void Start()
{
_parent = GameObject.Find("Example Assets").transform;
Instantiate();
}
private async void Instantiate()
{
await AddressablesLoader.InitAssets(_label, _createdObjs, _parent);
}
}
Fill the Label
field as Prefabs on the inspector.
Click Play
button and check out how is it going.
There are 3 modes to use addrssables on play mode.
To check out works on production environment, change Play Mode Script
to Use Existing Build (requires built groups).
Now we need to build our addressables.
To do this, select Build > New Build > Default Build Script
.
You could find files built in Assets\AddressableAssetsData\Windows
folder.
Click Play
button and check out how is it going.
Without build, you'll get the error message.
We could store & load built files from the server.
Here I would go with AWS S3.
In this guide, I'll not explain about setup for cloud service.
Check out this reference if you need.
Select Profile:Default > Manage Profiles
.
In Addressable Profiles window, select Create > Profile
.
Rename created profile as you want.
On created profile, replace RemoteLoadPath
value from http://localhost
to your bucket base url.
Right click on created profile and select Set Active
.
Select Tools > Inspect system Settings
.
On the inspector, check the box for Build Remote Catalog
.
Set Build Path
to RemoteBuildPath.
Also set Load Path
to RemoteLoadPath.
Right click on Prefabs
group and select Inspect Group Settings
.
On the inspector, set Build Path
to RemoteBuildPath.
Also set Load Path
to RemoteLoadPath.
As we did before, select Build > New Build > Default Build Script
.
You could find files built for remote in ServerData\StandaloneWindows
folder.
The files should be .json
, .hash
and .bundle
.
Running at this time would cause errors because Unity tries to get remote groups from the server.
So let's upload our files.
On AWS Console S3 Service, Go into your bucket root.
Upload StandaloneWindows
folder to your bucket.
Click Next
button to go to Set permissons
Section and Set Manage public permissions
to Grant public read access to object(s).
Click Upload
button to finish.
Make any changes on your asset.
Here I changed the paint supply's material to something else.
To update assets, select Build > Update a Previous Build
.
Select addressables_content_state.bin
file in Assets\AddressableAssetsData\Windows\
folder.
Upload files changed (.json
, .hash
, .bundle
) into your bucket's StandaloneWindows
folder.
Don't forget to grant public read permissions as we did before.
Now you can store & load assets (which's load path is configured to remote) from the server.
Also You don't need to create a new build for updating assets anymore. π