# Getting Started with Addressable Assets ## Addressable Asset SystemGetting started https://docs.unity3d.com/Packages/com.unity.addressables@1.1/manual/AddressableAssetsGettingStarted.html ## Tutorial ### Step1: Download Addressables Download Addressables from ```Package Manager``` ![](https://i.imgur.com/cLiISwB.png) ### Step2: Create new Group ![](https://i.imgur.com/NWOKhFw.png) ### Step3: Drag assets into group ![](https://i.imgur.com/afk7bHx.png) ### Step4: Set Profiles Select ```Assets/AddressableAssetsData/AddressableAssetSettings```. And click ```Manager profiles``` ![](https://i.imgur.com/APrxllh.png) ### Step5: Create Profile ![](https://i.imgur.com/TNl8NuU.png) ### Step6: Custom Path Set ```RemoteBuildPath``` and ```RemoteLoadPath``` ![](https://i.imgur.com/qNkpH5L.png) ### Step7: Set Remote path Set ```Build Path``` to RemoteBuildPath and ```Load Path``` to RemoteLoadPath ![](https://i.imgur.com/xcvkU0N.png) ### Step8: Set Group config If you create a new group, you might need to change path to each group. * Default local group ![](https://i.imgur.com/XGHH7eI.png) * Packed Assets ![](https://i.imgur.com/wrEA8nC.png) ### Step9: Build Assets ![](https://i.imgur.com/TJU9OYd.png) ## Load Addressable Asset Sample Sample ``` using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.ResourceManagement.ResourceLocations; using UnityEngine.SceneManagement; public class AddressableTest : MonoBehaviour { public AsyncOperationHandle loadMapOperation; [ContextMenu("LoadScene")] public void LoadScene() { //UnityEngine.Caching.ClearCache(); StartCoroutine(LoadScene_Co()); } [ContextMenu("LoadPrefab")] void LoadPrefab() { Addressables.LoadAssetAsync<GameObject>("Assets/M2 x 0.4mm Thread 5mm LONG SOCKET HEAD CAP SCREW.STL.prefab").Completed += OnLoadPrefabDone; } private void OnLoadPrefabDone(AsyncOperationHandle<GameObject> obj) { // In a production environment, you should add exception handling to catch scenarios such as a null result. var myGameObject = obj.Result; Instantiate(myGameObject); print(myGameObject.name); } IEnumerator LoadScene_Co() { var cc = "https://addessablebundlebucket.s3.ap-northeast-1.amazonaws.com/StandaloneWindows64/catalog_2022.02.11.08.45.44.json"; bool catUpdate = false; Addressables.LoadContentCatalogAsync(cc).Completed += (res) => { catUpdate = true; }; while (!catUpdate) yield return null; loadMapOperation = Addressables.LoadSceneAsync("Assets/RPG_FPS_game_assets_industrial/Map_v2.unity", LoadSceneMode.Additive); yield return null; var percentDone = 0.0f; while (!loadMapOperation.IsDone) { percentDone = Mathf.Floor(loadMapOperation.PercentComplete * 100.0f); Debug.Log($"percentDone - {percentDone}"); yield return null; } // else scene should load automatically, right? } } ``` Load Prefab from json ``` using System.Collections; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class FileManager : MonoBehaviour { SerializeField] private UnityEditor.AddressableAssets.Settings.AddressableAssetSettings settings; public List<string> prefabNamelist = new List<string>(); private string jsonPath = string.Empty; private void Start() { // Get load/build path var group = AddressableAssetSettingsDefaultObject.Settings.FindGroup("Packed Assets"); BundledAssetGroupSchema schema = group.GetSchema<BundledAssetGroupSchema>(); var loadpath = schema.LoadPath.GetValue(settings); //print($"Loadpath: {schema.LoadPath.GetValue(settings)}"); //print($"Buildpath: {schema.BuildPath.GetValue(settings)}"); var info = new DirectoryInfo(loadpath); var fileInfo = info.GetFiles(); foreach (var file in fileInfo) { if (file.Extension.Equals(".json")) jsonPath = Path.Combine(loadpath, file.Name); } print($"Load path: {jsonPath}"); GetPrefabFromJson(); } public void Load(string address) { StartCoroutine(LoadByName(address)); } private IEnumerator LoadByName(string name) { var cc = jsonPath; bool catUpdate = false; Addressables.LoadContentCatalogAsync(cc).Completed += (res) => { catUpdate = true; }; while (!catUpdate) yield return null; AsyncOperationHandle<GameObject> handle = Addressables.LoadAssetAsync<GameObject>(name); handle.Completed += obj => { var myGameObject = obj.Result; Instantiate(myGameObject); }; print("LoadByName:{name}Done"); } private IEnumerator LoadAll() { var cc = jsonPath; bool catUpdate = false; Addressables.LoadContentCatalogAsync(cc).Completed += (res) => { catUpdate = true; }; while (!catUpdate) yield return null; foreach (var i in prefabNamelist) { Addressables.LoadAssetsAsync<GameObject>(i, obj => { Debug.Log(obj.name); GameObject go = Instantiate(obj); }, false); } print("LoadAll:Done"); } private bool GetPrefabFromJson() { prefabNamelist.Clear(); StreamReader reader = new StreamReader(jsonPath); string txt = reader.ReadToEnd(); var resultString1 = Regex.Split(txt, "prefab_", RegexOptions.IgnoreCase); //print(resultString1[1]); for (int i = 1; i < resultString1.Length; i++) { var resultString2 = resultString1[i].Split('"'); //print(resultString2[0]); prefabNamelist.Add($"Assets/prefab_{resultString2[0].Trim()}"); } reader.Close(); return true; } } ```