Custom Build Systems

If you're using a custom build system for making builds in Unity, this is for you.

πŸ“˜

This article is only relevant to you if you are using a custom solution or pipeline for making builds in Unity. It is not a required step for getting started with Trail, but can be a big quality-of-life integration to have!

In this article you'll find (3) ways of integrating:

  1. Adding your build system to Trail's SDK UI
  2. Triggering the Trail SDK from your Build System
  3. Building for Trail without the SDK UI

πŸ“˜

Builds - not releases!

When you upload a build to Trail it'll be handled by the Trail Game Manager. It will not be a release and never be automatically published for your players to play. In the Game Manager you can playtest, configure, and release any builds you have uploaded!

Adding your Build System to Trail's SDK UI

You can use this to trigger your own build system when pressing any of the "Build" buttons in the Trail Editor Extension.

This is not a requirement for making builds for Trail, it's simply a convenience.

EventsDescription
TrailBuild.CustomBuildThe event that can be used to override the default build pipeline used by Trail. The method provided needs to return a BuildReport, so Trail can store information about the build for easier uploading.
TrailBuild.OnPreBuildThe event that that can be used to run any custom code before a build.

Example:

[InitializeOnLoadMethod]
private static void SetupBuildPipeline()
{
   Trail.TrailBuild.CustomBuild += MyBuildPipeline;
}

private static BuildReport MyBuildPipeline()
{
   BuildPlayerOptions options = new BuildPlayerOptions();

   options.scenes = EditorBuildSettings.scenes
       .Where(x => x.enabled)
       .Select(x => x.path)
       .ToArray();

   options.target = BuildTarget.WebGL;
   options.targetGroup = BuildTargetGroup.WebGL;
   options.options = BuildOptions.ShowBuiltPlayer;
   options.locationPathName = "Builds/WebGL";

   return UnityEditor.BuildPipeline.BuildPlayer(options);
}

Triggering the Trail SDK from your Build System

Useful for example if you want to finish your scripted build process with uploading the build to Trail. This method effectively triggers the "build"-feature of the Trail SDK programmatically.

MethodDescription
TrailBuild.RunFullReport();This method will run through all the reports in Report Window to verify how many required issues exist. Returns the number of problems that need to be fixed before uploading to Trail.
TrailBuild.Build();This method will run the same operation as the Build button provided in the Trail SDK Editor. This will further update the Trail SDK Editor build-cache so you can upload the build without providing a path. Returns BuildReport if the build was not canceled.
TrailBuild.Upload(string description);This method will attempt to upload the latest build, with a description, to Trail if any build exists.
TrailBuild.Upload(string path, string description);This method will attempt to upload a build, with a description, on the provided path to Trail.
TrailBuild.HasBuild();A convenient method to verify if the build cache exists and the directory of the build exists.
This method does not check if all files exist in the build.

Example:

private static void ExampleBuildAndUpload()
{
   var requiredIssues = Trail.TrailBuild.RunFullReport();
  if (requiredIssues > 0)
  {
        Debug.LogError($"You have {requiredIssues} that needs to be fixed before building for Trail.");
        return;
  }
   var report = Trail.TrailBuild.Build();
   if (report.summary.result == BuildResult.Succeeded)
   {
       Trail.TrailBuild.Upload();
   }
}

Ex: Building for Trail without the SDK UI

This example shows how you can upload builds to Trail without using the SDK UI - fixing settings and Trail authentication (login) programmatically.

public async static void BuildTrail()
    {
        BuildPlayerOptions opts = new BuildPlayerOptions();
        opts.scenes = scenes;
        opts.locationPathName = "Local/Trail/Build";
        opts.target = BuildTarget.WebGL;
        opts.options = BuildOptions.None;
        var report = BuildPipeline.BuildPlayer(opts);

        var password = Environment.GetEnvironmentVariable("PASSWORD");
        var email = Environment.GetEnvironmentVariable("EMAIL");
        var description = Environment.GetEnvironmentVariable("BUILD_DESCRIPTION");

        var loginReq = new Trail.CLI.LoginRequest();
        var loginRes = await loginReq.Login(email, password);
        if (loginRes.Success == false)
        {
            throw new Exception(loginRes.ErrorMessage);
        }
        var uploadReq = new Trail.CLI.UploadBuildRequest();
        var uploadRes = await uploadReq.UploadBuild(report.summary.outputPath, description);
        if (uploadRes.Success == false)
        {
            throw new Exception(uploadRes.ErrorMessage);
        }
    }