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. Dismiss Notice

Question How to trigger "Update A Previous Build" from editor script?

Discussion in 'Addressables' started by ZammyIsOnFire1, Jun 29, 2022.

  1. ZammyIsOnFire1

    ZammyIsOnFire1

    Joined:
    Sep 29, 2014
    Posts:
    19
    Hello everyone,

    I am building a system where WebGL minigames can be styled/themed and I am trying to use Addressables so that we do not need to make custom builds for each customization.

    I have managed to get it working if I am manually triggering "Update A Previous Build" from "Addressables Groups" menu. When I try to simulate it with editor script I am failing. It triggers new build and it only works if a previous is updated.

    Here is my attempt:
    Code (CSharp):
    1.      
    2.         var input = new AddressablesDataBuilderInput(AddressableAssetSettingsDefaultObject.Settings);
    3.         var updateBuild = new AddressablesBuildMenuUpdateAPreviousBuild();
    4.         updateBuild.OnPrebuild(input);
    5.         AddressableAssetSettings.BuildPlayerContent(out AddressablesPlayerBuildResult result);
    6.         if (!string.IsNullOrEmpty(result.Error))
    7.         {
    8.             Debug.LogError(result.Error);
    9.             return;
    10.         }
    11.         updateBuild.OnPostbuild(input, result);
     
  2. ZammyIsOnFire1

    ZammyIsOnFire1

    Joined:
    Sep 29, 2014
    Posts:
    19
    On further research I found the way to do it. I used
    ContentUpdateScript
    . Here is a sample code:

    Code (CSharp):
    1.         var group = AddressableAssetSettingsDefaultObject.Settings.FindGroup("Remote");
    2.         var path = ContentUpdateScript.GetContentStateDataPath(false);
    3.         var result = ContentUpdateScript.BuildContentUpdate(group.Settings, path);
    4.         if (!string.IsNullOrEmpty(result.Error))
    5.         {
    6.             Debug.LogError(result.Error);
    7.         }
     
  3. denmla1001

    denmla1001

    Joined:
    Nov 29, 2021
    Posts:
    13
    Tnx a lot
    Did you found a way to get only the new files from that update?
    I wanted to automate updates as much as possible