Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Addressable Settings in Editor Script

Discussion in 'Addressables' started by MrPoggle, Oct 10, 2022.

  1. MrPoggle

    MrPoggle

    Joined:
    Oct 29, 2020
    Posts:
    5
    Hey there, I have been looking everywhere and I cannot find anything to help me with this problem. I have an editor script that changes a lot of elements in my project between a release mode and a dev mode so that development tests do not interfere with live users. I am trying to include in this editor script a change before build from one profile to another in Addressable Asset Settings.

    The setting is on the Addressable Asset Settings scriptable object under profiles. It is very easy to click Profile In Use and change it to a different one but I would really like to consolidate every change needed for different build types into one spot. So I need to change the currently selected Profile In Use in C# using an editor script.

    m_AssetSettings.activeProfileId = "DevMode"; doesn't seem to do anything when run in the editor

    Thanks in advance for any help, it would be much appreciated.
     
  2. LuGus-Jan

    LuGus-Jan

    Joined:
    Oct 3, 2016
    Posts:
    169
    Setting an active profile is not done using its name, but by using the ID of a profile. If you check out the Addressable Asset Settings object in the debug inspector, you can see the ID associated with the name.



    You can switch the active profile based on the name using this snippet:

    Code (CSharp):
    1. AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
    2. AddressableAssetProfileSettings profile = settings.profileSettings;
    3. string profileID = settings.profileSettings.GetProfileId(profileName);
    4. settings.activeProfileId = profileID;
    Hope that helps!
     
  3. MrPoggle

    MrPoggle

    Joined:
    Oct 29, 2020
    Posts:
    5
    Thanks this is what I ended up doing!