Change Addressables Profile using Unity Cloud Build Environment Variables

Hi all,

I use UCB and I am start to use addressables on my project.
In my case I have UCB pipelines to build the game regarding the environment that we want (Dev/Staging/Production).

Also reflecting that I have Addressables profiles reflecting those environments.
My problem is:
I am trying to change those profiles with UCB Environment Variables, so each build will point to the respective Addressables profile.

I was trying to use a IPreprocessBuildWithReport in order to change it on UCB.
However it seems that the AddressableAssetSettingsDefaultObject.Settings is not being changed.

Here is the code:

public void OnPreprocessBuild(BuildReport report)
    {
        var profileSettings = AddressableAssetSettingsDefaultObject.Settings.profileSettings;
        string activeProfileName = "Dev";
#if UNITY_CLOUD_BUILD
        Debug.Log("[AddressablesProfileSelector] Unity Cloud Build");
        var profile = Environment.GetEnvironmentVariable("ADDRESSABLES_PROFILE");
       
        activeProfileName = profile != null && !profile.Equals(string.Empty) ? profile : "Dev";
#elif UNITY_EDITOR
        activeProfileName = "Dev";
        Debug.Log("[AddressablesProfileSelector] Unity Editor");
#endif
        var id = profileSettings.GetProfileId(activeProfileName);
        Debug.Log(string.Format("[AddressablesProfileSelector] Profile: {0}", activeProfileName));
        AddressableAssetSettingsDefaultObject.Settings.activeProfileId = id;
        EditorUtility.SetDirty(AddressableAssetSettingsDefaultObject.Settings);
    }

I don’t know if my flow is wrong, or if I am missing some step on that.

Please, any help will be great!

I’ll flag this with the team for some guidance!

1 Like

well, I’m not sure exactly why what you’re doing isn’t working, but Cloud Build provides an interface for setting the profile. You just type it in on the web UI. Is there a reason this wouldn’t work for you?

Hi @unity_bill thank you for the answer.

I was trying to make separated pipelines configs. One for the game and other for the addressables build. That is why for the game I was trying to get the environment variables.

I am still investigating the problem, but I think mine was related to other issues. Looking at the forum I could see that in order for this to work I should put the built addressables files to Library folder and also put the link file into Assets folder.