Search Unity

Is there way to access existing addressable asset setting?

Discussion in 'Addressables' started by VaygrEmpire, Nov 4, 2019.

  1. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    I've been looking at documentation for hours and can't find relevant method that can access existing addressable asset setting object. I'm trying to access it during custom build script so that I can build from specific profile. Anyone know how to access existing addressable asset setting in code? (preferably through addressable system)
     
  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey @VaygrEmpire I think what will help you out is
    Code (CSharp):
    1. AddressableAssetSettingsDefaultObject.Settings
    Hope that helps! Let me know if you still have trouble.
     
  3. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    Thanks, @DavidUnity3d ! But I have another question regarding addressable asset system. I'm trying to build it in custom build script and when I called
    Code (CSharp):
    1. AddressableAssetSettings.BuildPlayerContent();
    , Editor gave me null reference in path. So I'm trying to access existing addressable asset setting object's build path.

    How do I access paths under profile setting and pass it through BuildPlayerContent()?

    **********EDIT***************

    Actually I figured out how to get path. Now I just need to find a way to pass it to somewhere so that BuildPlayerContent() gets working...
     
    Last edited: Nov 4, 2019
  4. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    So the Addressables Build Path is not something we current allow modifications to. Are you saying BuildPlayerContent() is failing with an error? BuildPlayerContent() should build everything to
    Code (CSharp):
    1. Library/com.unity.addressables/StreamingAssetsCopy/aa/" + YourPlatformName
     
  5. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    @DavidUnity3d yeah when I just put following lines of codes I get path error...


    or so I thought. Fixed it but now I'm more confused. So on default setting I have 2 profiles: Default and Remote. Each of them have different paths designated. When I build, how does it know which profile I want it to build?

    Code (CSharp):
    1. var profileSetting = UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings.profileSettings;
    2.         var profileID = profileSetting.GetProfileId("Remote");
    3.         var names = profileSetting.GetVariableNames();
    4.         for (int i = 0; i < names.Count; i++)
    5.         {
    6.             if (profileID == profileSetting.GetProfileId("Remote"))
    7.             {
    8.                 AddressableAssetSettings.BuildPlayerContent();
    9.             }
    10.         }  
    I tried above but it builds for both Default and Remote profiles.
     
    arturchmielsperasoft likes this.
  6. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    upload_2019-11-5_11-32-32.png

    So it should pull the build paths and load paths from the active profile set here.

    Apologies if my previous comment was confusing. I think I misunderstood and thought you were trying to set the BuildPath property in a script.
     
  7. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    that was where I was going actually until your replied so nope you were correct on the issue.

    Thanks! Is it possible to build without setting anything in that Addressable Groups window but setting things straightly in code only? trying to create automated addresable asset build here.
     
  8. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    So, I think what you'll have to do is get the Addressable group, get the BundledAssetGroupSchema and then set the build path of that group before calling build content. Something like this should get what you're going for

    Code (CSharp):
    1. var group = AddressableAssetSettingsDefaultObject.Settings.FindGroup("groupName");
    2. group.GetSchema<BundledAssetGroupSchema>().BuildPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, "MyBuildPath");
    Hope that helps! Let me know if you still have trouble.
     
    Endahs, Kolja_Lubitz and tokar_dev like this.
  9. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    Hmm, that's one way to build it, but I got curious with another way to build - through profile. I was able to changing profile setting in script, but calling BuildPlayerContent() ended up building stuff into several folders outside Assets directory. I assume when BuildPlayerContent() is called, it builds to Local or Remote path based on Build Remote Catalog bool state? What's the best approach to call Build once you change profile setting to something else, then build to that profile's build path?

    Or am I back to un-modifiable build path problem again?
     
    tokar_dev likes this.
  10. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Ah, yes, so in that case you should be able to do
    Code (CSharp):
    1. AddressableAssetSettingsDefaultObject.Settings.activeProfileId = AddressableAssetSettingsDefaultObject.Settings.profileSettings.GetProfileId(n);
    where "n" is the string name of your profile you're trying to change it to.

    It may also be necessary to set the settings object as dirty with
    Code (CSharp):
    1. EditorUtility.SetDirty(AddressableAssetSettingsDefaultObject.Settings);
    but I haven't tested it and this may not be required. Just something to try if need be.
     
  11. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    Code (CSharp):
    1. var addressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings;  
    2. var desiredProfileSelection = "Remote";
    3.         if (desiredProfileSelection == addressableAssetSettings.activeProfileId)
    4.         {
    5.             Debug.Log("current profileID is " + desiredProfileSelection);
    6.         }
    7.         else
    8.         {
    9.             if (addressableAssetSettings.profileSettings.GetAllProfileNames().Contains(desiredProfileSelection))
    10.             {
    11.                 if (addressableAssetSettings.activeProfileId != desiredProfileSelection)
    12.                 {
    13.                     addressableAssetSettings.activeProfileId = desiredProfileSelection;
    14.                     Debug.Log("changing profileID to " + addressableAssetSettings.activeProfileId);
    15.                     EditorUtility.SetDirty(AddressableAssetSettingsDefaultObject.Settings);
    16.                     AddressableAssetSettings.BuildPlayerContent();
    17.                 }
    18.             }
    19.         }


    @DavidUnity3d I really appreciate all your help on this matter and I'm really sorry to keep bothering you..

    So what I'm trying to do is test custom build script using Addressable System. When I build with above code, what I expect is to be built at red circled build path. Instead, it builds outside Assets folder, not to mention it's not building to correct path - red circled one. I think it's building to Profile: Default build path rather than changed profile's build path.

    What am I doing wrong? And how can I fix this?
     
    review2 likes this.
  12. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey no problem at all. I'm sorry I was missing something in what I said you needed to do. If you change your code from
    Code (CSharp):
    1. addressableAssetSettings.activeProfileId = desiredProfileSelection;
    2.                     Debug.Log("changing profileID to " + addressableAssetSettings.activeProfileId);
    3.                     EditorUtility.SetDirty(AddressableAssetSettingsDefaultObject.Settings);
    4.                     AddressableAssetSettings.BuildPlayerContent();
    to

    Code (CSharp):
    1. var id = addressableAssetSettings.profileSettings.GetProfileId(desiredProfileSelection);
    2.         addressableAssetSettings.activeProfileId = id;
    3.         Debug.Log("changing profileID to " + addressableAssetSettings.activeProfileId);
    4.         AddressableAssetSettings.BuildPlayerContent();
    it should work. That code worked for me at least. The thing I forgot was that you need to convert the group name to the groups internal id (addressableAssetSettings.profileSettings.GetProfileId(desiredProfileSelection))

    Let me know if you still have trouble!
     
  13. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40

    Thanks! It finally worked! Built to correct location!
     
    davidla_unity likes this.
  14. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    @DavidUnity3d Question just popped up regarding changing build path. So it is not possible to change build path automatically with addressable? Say, if there's difference between versions it'll create new folder and build it there. Is such thing possible?
     
  15. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    So, I can check and see if there's a better solution that has been implemented in the past but off the top of my head I would say you would need to do what we discussed before and change the build path on the group to include the version number.

    I will say I seem to remember some users having trouble with updating a build if they were building to new directories every time but I can't remember exactly what the issue was. Just something to keep in mind.

    I know we can parameterize parts of the build and load paths but I'll have to look into if it's easily possible to add custom variables to use with this.
     
  16. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    @DavidUnity3d Is it also possible to change the name of the build? Currently when you build it is named as "catalog" + version numbers. Is it possible to customize "catalog" part?



    Moreover, is there documentation page for "Bundle Asset Provider Types"?



    Thanks for help!
     
  17. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    No, it isn't possible currently to change the "catalog" part.

    Doing a quick scan of our documentation it doesn't appear that we do. We're working on getting better docs updated/added. If you click the Documentation link in the Addressables section in Package Manager it should take you to what documentation we currently have. Though I've heard that Package Manager doesn't always take you to the most updated docs sadly.

    No problem, happy to help.
     
  18. senfield

    senfield

    Joined:
    Apr 1, 2019
    Posts:
    31
    At least in version 1.2.2 I am able to change the catalog name. You check build remote catalog and then put something in player version override and it appends that to your catalog... so you have like catalog_MyPlayerVersionOverrideString.json

    Both of those settings can also be configured via editor scripts as well.
     
  19. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    thanks but I meant specifically that "catalog" part
     
  20. skwsk8

    skwsk8

    Joined:
    Jul 6, 2014
    Posts:
    35
    @DavidUnity3d We're developing using several different environments such as Dev, Test, Live and use a standard CI practice of build once and promote those builds up the environment heirarchy as they pass various stages of testing. The problem is that each environment has a different URL, but the RemoteLoadPath seems to get built into the addressables build as a single URL.
    Is there a way to modify that at runtime?
    RemoteLoadPath: www.dev.somesite.com/[BuildTarget]
    runtime change this to be: www.live.somesite.com/[BuildTarget]

    Or is there some sort of variable lookup we could put into a config file using a custom variable?
    RemoteLoadPath: www.[Environment].somesite.com/[BuildTarget]
    config set Environment variable to be: "live" so it uses: www.live.somesite.com/[BuildTarget]
     
  21. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    @skwsk8 yes you can set the path at runtime.

    You would need to define your loadpath in the profile as something like
    {ServerSettings.AddressablesUrl}/[BuildTarget]

    The {} is a runtime variable. So we have a class
    ServerSettings
    with a static variable of
    AddressablesUrl
    .

    Our use case is once the use logs in, the server sends back the proper addressables url for whatever branch they are on, dev/test/prod etc.

    The only issue is once the addressables stuff inits, it cant be changed so you have to resolve it with your custom code before you do anything with addressables.

    You could also use some DEFINE functionality to set the url at compile time.

    For example in our project with our different build paths, dev/test/prod a custom platform define is turned on i.e. BUSINESS_PROD. You could use that method to change the urls based off of your build.
     
    skwsk8 likes this.
  22. javierfed

    javierfed

    Joined:
    Apr 10, 2015
    Posts:
    50
    I am trying to make my groups compile into their own folder, so that I can have a core bundle, and a bundle per group... to do this, I have been looking for a way to put the group name into the build/load path. any way to do this? I can't find it anywhere online.
     
    Bshsf_9527 likes this.
  23. Lalitsharma81

    Lalitsharma81

    Joined:
    Jun 19, 2020
    Posts:
    13
    @Jribs I am facing a similar issue ... our use case is our bundle files are stored on a private S3 bucket and we provide access to that bucket using presigned URL directly pointing to the .bundle file ...the problem is that we have an expiry time for URL and hence every time user hits a web request for bundle a new URL is generated on runtime and it is unique for every bundle file and due to architecture of addressables it cant change the urls once it gets lazy init.

    Due to this reason, we are moving back to asset bundle and downloading bundle files individually one by one ... but the maintenance work and content update is kinda hard to do on that basic level as we have over 100 assets, model, textures, etc and their dependencies also the work feels kinda trivial as addressable has already provided the solutions for grouping and content update without any code work.

    So is there any way where i can leverage any functionality to change bundle urls at runtime?
     
  24. spreddy_unity

    spreddy_unity

    Joined:
    Nov 13, 2020
    Posts:
    4
    @davidla_unity Is there a way to load asset of local group to load from remote after app release using Curly brackets in load path or loading remote catalog.
     
  25. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    Before we switched to addressables, we also used pre-signed urls because our buckets were private.

    We had to change and make them public.

    AFAIK there is no way to provide specific urls for individual bundles.

    I agree it is a pretty big drawback to addressables, but the memory management is so much better it was worth the trade off for us.
     
    Lalitsharma81 likes this.
  26. javierfed

    javierfed

    Joined:
    Apr 10, 2015
    Posts:
    50
    There is a way, and it is how I will be doing it from now on cause it works very well,
    you can use the <custom> setting, in conjunction with the profile variables, so you can set your bundle to build to / load from [BuildRemoteTargetBundle]/<custom Name> and it works just fine! this way our bundles and future bundles can be organized and the addressables asset catalog can be placed wherever it is convenient or necessary.