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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question How to define build environment variant (dev/release) for RemoveBuildPath?

Discussion in 'Addressables' started by novaVision, Jul 20, 2022.

  1. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    421
    I wish to keep 2 folder in ServerData folder for development build and for releases.
    I tried to implement it using static variable in static class same as I did it for RemoteLoadPath but it doesn't work.

    Ideally, the path shall be something like that:
    Code (CSharp):
    1. $"ServerData/{Application.platform}/{(Debug.isDebugBuild ? "Dev" : "Release")}/{Application.version.Replace('.', '_')}";
    as a result it should build to:
    ServerData/Android/Dev/1_2

    Is there a way define environment string at least (I assume app verison can be added the way I planned to)?
    Jsut testing I see that adding BuildVersion to the end of the default remote build path also doesn't work:
    Code (CSharp):
    1. ServerData/[BuildTarget]/[BuildVersion]
    builds to ServerData/Android/UnityEditor.bundleVersion


    To avoid multiple threads, will ask another question here as well because it's partially connected to the issue described above:

    So, let's imaging I would implement what I wish and I will have 2 folders (Dev/Release) with some sub-folders representing app versions (1_1, 1_2, etc). How can I update the build for any version later on? As we know to update the addressables build we need addressables_content_state.bin file. How can I keep multiple files? By default there is only 1 file which overrides each time on build update.
    In terms of version control I always can return to any previous version using git and use saved .bin file, but I still can't control dev/release builds.

    Is there any option to keep at least 2 files (for Dev/Release)?
     
    Last edited: Jul 20, 2022
  2. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    279
    Hi @novaVision I think this is what you wanted to achieve:
    1) Create a new profile variable called BuildVersion
    2) Set the value of BuildVersion to the full name of the bundleVersion variable

    upload_2022-7-29_10-47-29.png

    Docs about the profile variables syntax here: https://docs.unity3d.com/Packages/c...leAssetsProfiles.html#profile-variable-syntax

    You can also change the location where the content_state.bin file is created, using the "Content State Build Path" setting. If you're using Addressables 1.20+, this location is linked with your profile variables, and you can create variable for the subfolder.
    upload_2022-7-29_12-5-47.png

    For older versions "Content State Build Path" is just a modifiable string field. I can't remember if you can use profile variables with it, but you can try.
     
  3. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    421
    @pillakirsten thanks for your reply.

    I was on Addressables before 1.19.19 using 2021.3.7f1, and seems that was the latest officially supported Addressables version. However I installed 1.20.3 manually modifying manifest.json, because that dynamic Content State Build Path is really nice feature I was looking for. I hope this will not cause any issues later on.

    I also updated Build Version variable (I had it before, probably imported by a default and seems the value there was wrong - [UnityEditor.bundleVersion] instead of [UnityEditor.PlayerSettings.bundleVersion]. Probably that's the reason why my build path was wrong when I tried to use it.

    One more question here (I didnt' find the answer in docs) - is there any variable I can input tot the path in [] which defines the build environment? (production/development)? Similar how BuildTarget or BuildVersion defines?

    UPDATE
    I found several workarounds to solve it in this thread. Hope this will help someone
     
    Last edited: Aug 8, 2022
  4. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    421
    I still got the issue setting up custom content build path.
    Here is the code I use in static AppManager class

    Code (CSharp):
    1. public static string ContentStateBuildPath
    2.         {
    3.             get
    4.             {
    5.                 string buildTarget =  EditorUserBuildSettings.activeBuildTarget.ToString();
    6.                 string appVersion = string.Empty;
    7.                 string buildNumber = string.Empty;
    8.                 string path = string.Empty;
    9.  
    10.                 if (Debug.isDebugBuild)
    11.                 {
    12. #if UNITY_IOS
    13.                     buildNumber = PlayerSettings.iOS.buildNumber.ToString();
    14. #elif UNITY_ANDROID
    15.                     buildNumber = PlayerSettings.Android.bundleVersionCode.ToString();
    16. #endif
    17.                     path = $"AddressableAssetsData/{buildTarget}/{EnvironmentPath}/{buildNumber}";
    18.                 }
    19.                 else
    20.                 {
    21.                     appVersion = Application.version.Replace('.', '_');
    22.                     path = $"AddressableAssetsData/{buildTarget}/{EnvironmentPath}/{appVersion}";
    23.                 }
    24.  
    25.                 Debug.Log("content state build path: " + path);
    26.                 return path;
    27.             }
    28.         }
    But trying to build addressables build I got these errors:

    Code (CSharp):
    1. Assets\_Project\Scripts\AppManager.cs(77,39): error CS0103: The name 'EditorUserBuildSettings' does not exist in the current context
    2.  
    3. Assets\_Project\Scripts\AppManager.cs(87,35): error CS0103: The name 'PlayerSettings' does not exist in the current context
    As I understood the build runtime can't access these classes. But how can I replace them?
     
  5. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    279
    @novaVision You just need to wrap where you call 'EditorUserBuildSettings' and 'PlayerSettings' with UNITY_EDITOR defines. Or to make things easier just wrap the define around the entire property:
    # if UNITY_EDITOR
    public static string ContentStateBuildPath { ... }
    # endif

    This way the string will be evaluated correctly in AddresssableAssetSettings before the Addressables build is run.
    upload_2022-8-10_10-7-2.png
     
unityunity