Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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:
    15
    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. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    15
    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. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    15
    @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.
     
  6. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    15
    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. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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.
     
  9. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    15
    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?
     
  10. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    15
    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?
     
  12. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    15

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

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    15
    @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. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    15
    @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. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    81
    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:
    24
    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.