Search Unity

Failing to download from server

Discussion in 'Addressables' started by Tarrag, Aug 23, 2018.

  1. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Hi all, running addressables from local is fine but can't get it to work for remote having tried multiple things, the remote addressable asset does not download on built player.

    These are the steps I'm taking, can someone shed some light what Im doing wrong?
    Thank you for your help! Sergio (using Unity 2018.2.5f1, addressables 0.2.2)

    1. create new remote addressables group in Addressables window, setting its Buildpath:ServerData/StandaloneWindows64 and Loadpath:http://www.xxx.com/subDirectory/StandaloneWindows64 . I add wings.prefab, wings.fbx, wings.mat to this group and label it testObject. wings.prefab holds the fbx and material. These assets are sitting respectively in the Assets/Prefab, Assets/Models and Assets/Materials folders of my project

    2. Add script to a gameobject in scene. Set assetName to testObject. Debug shows system is picking up all addressable assets, e.g. the material console shows currentAssetName as Assets/Materials/WingsMat.mat. Im reusing demo scripts https://drive.google.com/file/d/19LlNLqMa9ZEJgjLogWcWxRsTvhHGU191/view

    Code (CSharp):
    1. public AssetLabelReference assetName;
    2. private List<IResourceLocation> assetList;
    3. public void Start()
    4.     {
    5.         Addressables.LoadAssets<IResourceLocation>(assetName.labelString, null).Completed += assetReady;
    6.     }
    7. void assetReady(IAsyncOperation<IList<IResourceLocation>> op)
    8.     {
    9.         assetList = new List<IResourceLocation>(op.Result);
    10.         StartCoroutine(SpawnWaves());
    11.     }
    12.  
    13. IEnumerator SpawnWaves()
    14.     {
    15.         yield return new WaitForSeconds(1f);
    16.         while (true)
    17.         {
    18.             int assetListIndex = 0;
    19.             for (int i = 0; i < assetListCount; i++)
    20.             {
    21.                 IResourceLocation currentAsset = assetList[assetListIndex];
    22.                 assetListIndex++;
    23.                 if (assetListIndex>= assetList.Count)
    24.                     assetListIndex = 0;
    25.                 Vector3 spawnPosition = new Vector3(UnityEngine.Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    26.                 Quaternion spawnRotation = Quaternion.identity;
    27. Addressables.Instantiate<GameObject>(currentAsset, spawnPosition, spawnRotation);
    28. yield return new WaitForSeconds(1f);
    29.             }
    30.             yield return new WaitForSeconds(1f);
    31. }}
    3. Set Addressables window Playmode to Packed. Then build player for windows. If I run player now as expected wings prefab doesn't spawn
    4. I upload into http://www.xxx.com/subDirectory/StandaloneWindows64/ the prefab, fbx and material with their respective .meta files. Also upload from ServerData/StandaloneWindows64 folder files catalog_1.has, catalog_1.json and the bundle file from my project ServerData/StandaloneWindows64 directory
    5. I run player I had previously built and the wings prefab does not show
     
    Last edited: Aug 23, 2018
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Next time use code tags for code. It is much more readable than just copy pasta.

    You should set your load path to http://www.xxx.com/subDirectory/[BuildTarget]
    Copy the folder that resides inside ServerData to the http://www.xxx.com/subDirectory/
    So it will become something like this: http://www.xxx.com/subDirectory/WindowsStandalone64
    So not http://www.xxx.com/subDirectory/ServerData/[BuildTarget]

    Also Addressables v0.2.2 seems to have some issues with deserializing the settings of the groups. So the BuildPath & LoadPath are reset constantly on Domain Reload (script changes or build).
    So make sure the settings are correct and then try to run again. Also check if you have any errors in the console.
     
    leollama likes this.
  3. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Thanks a bunch @MaskedMouse , edited the post :)

    I should note my project has both a local addressable asset and a remote asset. Local addressable loads fine.

    I tried all what you suggested above. I've also tested this with prior preview version of addressable assets. No warnings or errors at build shown in console. But remote assets still don't load.

    I copied the whole WindowsStandalone64 project dir into http://www.xxx.com/subDirectory/ .

    The assets int the remote group are not in the scene hierarchy cos they'll be instantiated, i'd expect removing them from the project as they'd be loaded from remote. I tried different variations where to place the project's prefab, material and fbx. Are the prefab/mat/fbx files supposed to be uploaded to remote http://www.xxx.com/subDirectory/[BuildTarget] and should I add the project's asset directory structure (subdirectories where prefab/fbx/material sit beneath Assets in the project); and the fbx/material/model .meta files too?

    I'm wondering, I'm confused by the Remote Packed Content Group section in the Addressable Asset System - Getting Started (https://docs.google.com/document/d/1Qdrhi3NdTR_ub5e1NVjzvijCcVlR56e_zCro41KHfyM/edit# )
    , page 21, says the assets will be downloaded from a URL via a UnityWebRequest. Do I need such script? It'd appear this is run internally and the Addressable Window takes care of this?

    Suggestions very welcome! Cheers, Sergio
     

    Attached Files:

    Last edited: Aug 23, 2018
  4. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Thats not how addressables work. Your addressable group contains your assets which will be packed into an asset bundle. That bundle is made at the build directory target that you give to the group. In your case ServerData/[BuildTarget]
    So you don't need the FBX, Prefab or any other asset on the server, just the [BuildTarget] directory. In your case WindowsStandalone64 in your subdirectory.
    What the Addressable Asset system will do is, handling the download, caching and updating the assets.
    When you use the addressable asset's Load method it will download the asset and load it into memory for use. But you could also just call Instantiate directly.

    You don't need to handle the UnityWebRequest, the addressable asset system does that for you.
    You just give the system the addressable you want to load or instantiate. The system will create a url based on the settings you give it. i.e. http://www.xxx.com/subDirectory/[BuildTarget] -> it will fill in the BuildTarget and the rest of the information that is stored in the addressable and catalog to create the URL that should lead to the absolute location of the bundle.
    so eventually the url will look like this http://www.xxx.com/subDirectory/Sta...48c83_08cba07dd241edc166be7f7e5ef8b9e9.bundle
    something similar. The StandaloneWindows64 should have some .bundle files in there. That's the file it requires to download from the server in order to run your content that you request. Any dependency is handled by them as well. So if you have another group with materials and textures, loading the prefab asset will automagically download the material & texture bundles as well that are required by the prefab.

    So the logical order what happens is (atleast what I think that happens aside from unity handling asset counts and other things):
    1. You have an AddressableAsset reference which you call LoadAsset or Instantiate of.
    2. The addressable system creates a URL using the information it has (from the addressable asset reference and catalog etc.)
    3. The system create a UnityWebRequest and downloads the bundle from the URL that is made (and dependencies from other bundles. Such as a material bundle, texture bundle if you have split those into addressable asset groups as well. Or selected Packed Seperately in the group settings)
    4. The system loads the asset from the bundle (LoadAsset method)
    5. The system instantiates the asset from the loaded asset from the bundle (Instantiate method)


    Code (CSharp):
    1. // Your reference to the addressable asset
    2. public AssetReferenceGameObject PrefabReference;
    3.  
    4. // Step 1 ~ 4 only, you have to handle instantiate yourself
    5. PrefabReference.LoadAsset<GameObject>().Completed += OnLoadCompleted;
    6.  
    7. // step 1 ~ 5, instantiation is handled for you
    8. PrefabReference.Instantiate<GameObject>().Completed += OnInstantiateCompleted;
     
    leollama likes this.
  5. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    I was going down a very confused path then haha!! That's really helpful @MaskedMouse , thanks a ton, gives me a lot to push forward :)
     
  6. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137