Documentation

Support

Use Build Automation's build manifest during runtime

Access build manifest data at runtime for analytics and bug reporting in Unity Build Automation.
Read time 2 minutesLast updated 16 hours ago

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 provides the manifest as a JSON formatted
TextAsset
. Build Automation stores the manifest as a game resource, accessible via
Resources.Load()
. The build manifest contains the following values:

Value

Properties

scmCommitId
The commit or changelist that was built.
scmBranch
The name of the branch that was built.
buildNumber
The Build Automation build number corresponding to this build.
buildStartTime
The UTC timestamp when the build process started.
projectId
The Unity project identifier.
bundleId
The
bundleIdentifier
configured in Build Automation (iOS and Android only).
unityVersion
The version of Unity that Build Automation used to create the build.
xcodeVersion
The version of XCode used to build the Project (iOS only).
cloudBuildTargetName
The name of the build target that was built.
The manifest TextAsset, called UnityCloudBuildManifest.json.txt, 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.

Use 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: MonoBehaviour
{
    void Start()
    {
        var manifest = (TextAsset) Resources.Load("UnityCloudBuildManifest.json.txt");
        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.txt
TextAsset.
BuildManifestObject
is an optional parameter to the pre-export invoked by Build Automation, if the
UnityCloudBuildManifest.json.txt
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
}
The following 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();
    }
}