Search Unity

Addressables are working as expected

Discussion in 'Addressables' started by Mazak, Jan 28, 2019.

  1. Mazak

    Mazak

    Joined:
    Mar 24, 2013
    Posts:
    226
    After taking three days to move 400mb of assets from /resources to addressables our tests are successful and I could not be happier. Today's build for our testing group is up and downloading assets from our server as expected.

    It was a lumpy three days and I am considering making a video of the steps because the steps are pretty precise. Unless done correctly in the right order everything can turn to a flaming pile of poo.

    I hope this helps both users and developers...

    Background:
    Galaxicus is a Realtime MMO Space Empire building game. We have assets that don't change very often such as planets and they have lived in /Resources. With a full download of the game which happens with major changes, the users have had to download everything time and time again.

    Our goals:
    1. Download from a Linux Centos 7 server.
    2. To remove the unchanging assets into \Galaxicus\Data folder so they are not downloaded by full installations.

    We are using Addressables Version 0.5.3

    I followed the instructions outlined in the video from Berlin's Unite (40+ times viewed).

    My steps:
    1. I moved the planets into a folder called zRemote/planets (the z allows the folder to end up a the bottom of my folder lists - ocd and all that jazz) After several tests, it was better to prepare the folders first.
    2. I marked all the planet prefabs as addressable, this auto created the addressable files.
    3. Now the part that is a bit confusing, you must setup your profile - this is the best time to do this.
    After several attempts I realized leaving the defaults is the best choice - go with the flow don't fight it.
    I only ended up changing the RemoteLoadPath. "http://patch.galaxicus.com/Galaxicus/[BuildTarget]"

    Note: Before you do this step I suggest pushing up to version control, this is where things can go wrong. It also allows you to revert and delete the AddressableAssetsData folder. You will need to re-check the prefabs as addressable and re-setup the paths in your profile.

    4. I updated my code with the following
    Code (CSharp):
    1.            
    2.             if (PlanetPreFab == null)
    3.             {
    4.                 // make sure this is turned off
    5.                 _destoryPlanet = false;
    6.                 const string baseFolder = "Assets/zRemote/planets/";
    7.  
    8.                 //DpeErrorLogWriter.WriteError("NS Creating Planet");
    9.                 //PlanetPreFab = DpePoolManager.Instance.SpawnNewObject(baseFolder + _planetData.PlanetFileName(), _planetData.PlanetFileName());
    10.                 IsPlanetLoading = true;
    11.                 Addressables.Instantiate<GameObject>(baseFolder + _planetData.PlanetFileName()+".prefab", transform).Completed +=
    12.                     delegate(IAsyncOperation<GameObject> obj)
    13.                     {
    14.                         if (obj == null || obj.Result == null)
    15.                         {
    16.                             DpeErrorLogWriter.WriteError("Unable to load " + baseFolder + _planetData.PlanetFileName());
    17.                             return;
    18.                         }
    19.  
    20.                         PlanetPreFab = obj.Result;
    21.                        
    22.                         PlanetPreFab.transform.localPosition = new Vector3(0f, 0f, 0f);
    23.                         PlanetPreFab.transform.localRotation = Quaternion.AngleAxis(0, Vector3.right);
    24.                         DpeExtensions.ChangeLayersRecursively(transform, Singleton.Instance.normalSpaceLayerID);
    25.                         planetRenderer = PlanetPreFab.GetComponent<Renderer>();
    26.  
    27.                };
    28.          }
    29.  
    30.  
    Since this seemed to work as expected, I moved to the next step

    4. I made a new group and moved the resources into it setting it to RemoveLoadPath
    upload_2019-1-28_16-47-23.png

    5. Build Player Content.
    Note: Before you do this step I suggest pushing up to version control, this is where things can go wrong. It also allows you to revert and delete the AddressableAssetsData folder.

    6. If you took the defaults you will have a ServerData/[BuildTarget] folder, push this content up to your website.
    upload_2019-1-28_17-5-51.png

    7. Now you need to edit the settings.json file... If you don't it will place your hash files (and all the bundles) into the persistent data folder not allowing users to do a full uninstall of your game.

    upload_2019-1-28_17-7-53.png

    upload_2019-1-28_17-13-14.png

    After installing the game this is the folder setup..
    upload_2019-1-28_17-22-50.png


    8. Now to modify where the assets are placed...
    Make this the first script to be read by your game:

    Code (CSharp):
    1.  
    2. public class AddressablesInit : MonoBehaviour
    3. {
    4.     // Start is called before the first frame update
    5.     void Awake()
    6.     {
    7.         Debug.Log(Caching.currentCacheForWriting.path);
    8.         var path = Singleton.Instance.GameDataFolder + "Assets/";
    9.            
    10.         if (!Directory.Exists(path))
    11.             Directory.CreateDirectory(path);
    12.  
    13.         var newCache = Caching.AddCache(path);
    14.  
    15.         //Make sure your new Cache is valid
    16.         if (newCache.valid)
    17.         {
    18.             //If you wanted to set your newly created cache to the active cache
    19.             Caching.currentCacheForWriting = newCache;
    20.         }            
    21.         Debug.Log(Caching.currentCacheForWriting.path);
    22.     }
    23. }
    24.  
    This worked for me, it might give you some ideas... but I am happy.

    Thanks to Bill at Unity for the videos, keep up the good work!

    Thanks

    David Baity

    Notes:
    1. Please double check for spelling mistakes - (http;//patcher.example.com) took two hours to debug ; instead of : - A test button would be helpful for websites to ensure everything is right before building, and pushing the files across the FTP server ( 9 times <grin> ).
    2. Do not tag folders hoping everything will work. This was our first attempt trying to shotgun the process, we were missing textures and other items. Just don't do it.
    2a. While trying to use the folders, It forced me to add a '.prefab' the above code reflects this and it may not be needed.
    3. Adding a download folder for the assets would be helpful - editing the settings.json is rather a pain.
    4. To restart the process: Revert your changes and delete the AddressableAssesData folder.
     
    JesOb, CharBodman, amcagurban and 3 others like this.