Build manifest

It’s often useful for your game’s runtime code to know key information about the build itself. Information like the name and number of the build is very useful when reporting bugs or tracking analytics. To help facilitate this, Build Automation injects a “manifest” into your game at build time, so that this key data is accessible later at runtime.

Build Automation manifest is provided as a JSON formatted TextAsset. This is stored as a game resource, accessible via Resources.Load(). The build manifest contains the following values:

ValueProperties
scmCommitIdThe commit or changelist that was built.
scmBranchThe name of the branch that was built.
buildNumberThe Build Automation “build number” corresponding to this build.
buildStartTimeThe UTC timestamp when the build process started.
projectIdThe Unity project identifier.
bundleIdThe bundleIdentifier configured in Build Automation (iOS and Android only).
unityVersionThe version of Unity that Build Automation used to create the build.
xcodeVersionThe version of XCode used to build the Project (iOS only).
cloudBuildTargetNameThe name of the build target that was built.

The manifest TextAsset, called UnityCloudBuildManifest.json, is written to the Assets/UnityCloud/Resources folder.

For local testing

To test the build manifest functionality locally, name your file UnityCloudBuildManifest.json.txt. Don’t commit this file to your project’s Assets/UnityCloud/Resources folder in your code repository because it might interfere with the Build Automation manifest file.

Using the manifest

You can access the manifest at runtime via:

Build manifest as JSON

You can access the Build Automation manifest as JSON at runtime. This Asset requires either custom parsing logic or the use of a third-party JSON parser.

The following example C# code demonstrates loading and parsing the build manifest with the MiniJSON parser on GitHub Gist:

using UnityEngine;
using System.Collections.Generic;
using MiniJSON;

public class MyGameObject: MonoBehavior
{
    void Start()
    {
        var manifest = (TextAsset) Resources.Load("UnityCloudBuildManifest.json");
        if (manifest != null)
        {
            var manifestDict = Json.Deserialize(manifest.text) as Dictionary<string,object>;
            foreach (var kvp in manifestDict)
            {
                // Be sure to check for null values!
                var value = (kvp.Value != null) ? kvp.Value.ToString() : "";
                Debug.Log(string.Format("Key: {0}, Value: {1}", kvp.Key, value));
            }
        }
    }
}

Build manifest as ScriptableObject

BuildManifestObject is a ScriptableObject you can use to access the values in the Build manifest via script, without needing to manually load the UnityCloudBuildManifest.json TextAsset.

It is an optional parameter to the pre-export invoked by Build Automation, if the UnityCloudBuildManifest.json TextAsset has not been written. For more information, see Manifest as JSON.

The following example C# code demonstrates a pre-export method that updates the bundleVersion in PlayerSettings based on the buildNumber provided in the manifest. For more information on pre-export methods, see Pre- and Post-export methods.

using UnityEngine;
using UnityEditor;
using System;

public class CloudBuildHelper : MonoBehaviour
{
    #if UNITY_CLOUD_BUILD
        public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
        {
            PlayerSettings.bundleVersion = string.Format("1.0.{0}", manifest.GetValue<int>("buildNumber"));
        }
    #endif
}

This is the public interface for the BuildManifestObject class:

namespace UnityEngine.CloudBuild
{
    public class BuildManifestObject : ScriptableObject
    {
        // Try to get a manifest value - returns true if key was found and could be cast to type T, otherwise returns false.
        public bool TryGetValue<T>(string key, out T result);
        // Retrieve a manifest value or throw an exception if the given key isn't found.
        public T GetValue<T>(string key);
        // Set the value for a given key.
        public void SetValue(string key, object value);
        // Copy values from a dictionary. ToString() will be called on dictionary values before being stored.
        public void SetValues(Dictionary<string, object> sourceDict);
        // Remove all key/value pairs.
        public void ClearValues();
        // Return a dictionary that represents the current BuildManifestObject.
        public Dictionary<string, object> ToDictionary();
        // Return a JSON formatted string that represents the current BuildManifestObject
        public string ToJson();
        // Return an INI formatted string that represents the current BuildManifestObject
        public override string ToString();
    }
}