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
TextAssetResources.Load()Value | Properties |
|---|---|
| The commit or changelist that was built. |
| The name of the branch that was built. |
| The Build Automation build number corresponding to this build. |
| The UTC timestamp when the build process started. |
| The Unity project identifier. |
| The |
| The version of Unity that Build Automation used to create the build. |
| The version of XCode used to build the Project (iOS only). |
| The name of the build target that was built. |
Assets/__UnityCloud__/ResourcesFor local testing
To test the build manifest functionality locally, name your fileUnityCloudBuildManifest.json.txtUse 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
ScriptableObjectBuildManifestObjectScriptableObjectUnityCloudBuildManifest.json.txtBuildManifestObjectUnityCloudBuildManifest.json.txtbundleVersionPlayerSettingsbuildNumberThe following is the public interface for theusing 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 }
BuildManifestObjectnamespace 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(); } }