Search Unity

Addressables with custom BuildPlayer script

Discussion in 'Addressables' started by Zenix, May 28, 2019.

  1. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    I have a custom build script I use to build the player, which basically sets a bunch of variables and then calls BuildPipeline.BuildPlayer.

    Since switching to Addressables, this no longer works. Although it still produces a build, when I run it no Addressable assets load. The last log message I get is 'Addressables - initialization complete.'

    If I build the player through the standard Unity menu everything works fine.

    I'm wondering if this is expected? Is BuildPlayer meant to work with Addressables or not? I can see my bundles have been copied over correctly to the output folder.

    I thought maybe I was meant to switch over to the new Scriptable Render Pipeline, but I can't find any documentation on that related to building a player, only to building the bundles.
     
  2. johnseghersmsft

    johnseghersmsft

    Joined:
    May 18, 2015
    Posts:
    28
    This is what I use for building Addressables runtime data. I created this code around the 0.4.x timeframe, so it might be out of date, but it will hopefully get you pointed in the right direction.

    The AddressableAssetSettingsDefaultObject.Settings object has an ActivePlayerDataBuilder object that has a BuildData<AddressablesPlayerBuildResult>() method.

    Code (CSharp):
    1.  
    2. public static void BuildWindowsApp()
    3. {
    4.     // Set various option such such as path, levels, version
    5.  
    6.     var buildPlayerOptions = new BuildPlayerOptions
    7.     {
    8.         scenes = levels,
    9.         locationPathName = path,
    10.         target = BuildTarget.StandaloneWindows64,
    11.         targetGroup = BuildTargetGroup.Standalone,
    12.         options = BuildOptions.None
    13.     };
    14.     PrepareRuntimeData(buildPlayerOptions, version);
    15.     var result = BuildPipeline.BuildPlayer(buildPlayerOptions);
    16. }
    17.  
    18. public static void PrepareRuntimeData(BuildPlayerOptions buildOptions, string version)
    19. {
    20.     var settings = AddressableAssetSettingsDefaultObject.Settings;
    21.     if (settings == null)
    22.     {
    23.         return;
    24.     }
    25.  
    26.     var context = new AddressablesBuildDataBuilderContext(
    27.         settings,
    28.         buildOptions.targetGroup,
    29.         buildOptions.target,
    30.         (buildOptions.options & BuildOptions.Development) != BuildOptions.None,
    31.         false,
    32.         version ?? settings.PlayerBuildVersion);
    33.  
    34.     settings.ActivePlayerDataBuilder.BuildData<AddressablesPlayerBuildResult>(context);
    35. }
    36.  
     
  3. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    Thanks, I'll check it out.