Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressables do not work in build #36

Closed
AldeRoberge opened this issue Jan 4, 2024 · 3 comments
Closed

Addressables do not work in build #36

AldeRoberge opened this issue Jan 4, 2024 · 3 comments

Comments

@AldeRoberge
Copy link

When building manually, everything works fine.
But when I build using SuperUnityBuild, it seems like the addressables arent included in the build. I get a bunch of "missing element with given key" at runtime when doing Addressables.LoadAsync...
Am I missing a step in the build config?

@celojevic
Copy link

You need to build addressables along with every build. I just made a script with it that you need to add to the Post-Build actions in the SUB window:

image

using SuperUnityBuild.BuildTool;

using System;

using UnityEditor;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Build;
using UnityEditor.Build.Pipeline.Utilities;

using UnityEngine;

namespace SuperUnityBuild.BuildActions
{

    public class UploadAddressablePostBuild : BuildAction, IPostBuildPerPlatformAction
    {

        [Tooltip("True to upload the built addressables to your CCD. You must have this already set up.")]
        [SerializeField] private bool _uploadToCcd=true;

        public override void PerBuildExecute(BuildReleaseType releaseType, BuildPlatform platform, 
            BuildArchitecture architecture, BuildScriptingBackend scriptingBackend, 
            BuildDistribution distribution, DateTime buildTime, ref BuildOptions options, 
            string configKey, string buildPath)
        {
            var settings = AddressableAssetSettingsDefaultObject.Settings;

            // NOTE: you need to modify this to fit your addressable profile names
            string profileName = platform.platformName == "PC" ? "Windows" : platform.platformName;
            // set the active profile based on platform
            string profileId = settings.profileSettings.GetProfileId(profileName);
            settings.activeProfileId = profileId;
            Debug.Log($"Setting active profile with name '{profileName}' to ID: " + settings.activeProfileId);

            // addressables is currently bugged, so we have to clear the cache before building
            // otherwise it'll get stuck in a dependency loop
            var activeBuilder = settings.ActivePlayerDataBuilder;
            AddressableAssetSettings.CleanPlayerContent(activeBuilder);
            BuildCache.PurgeCache(false);
            Caching.ClearCache();

            // this will build your addressables based on your profile settings
            AddressableAssetSettings.BuildPlayerContent(out AddressablesPlayerBuildResult result);
            Debug.Log("Err: " + result.Error);

            // this will upload the addressables to your CCD if true
            if (_uploadToCcd)
            {
                var builderInput = new AddressablesDataBuilderInput(settings);
                var task = CcdBuildEvents.Instance.UploadAndRelease(builderInput, result);
                task.ContinueWith(t =>
                {
                    Debug.Log("Upload and release succeeded: " + t.Result);
                });
            }
        }

    }

}

@MadhurG-Hexaware
Copy link

@celojevic can you provide script "CcdBuildEvents" as it is referenced in above script or any other generic way to upload stuff?

@celojevic
Copy link

@celojevic can you provide script "CcdBuildEvents" as it is referenced in above script or any other generic way to upload stuff?

That script is part of the unity CCD management package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants