Adding Commands

How to add a command to an automation project for AutomationTool.

Choose your operating system:

Windows

macOS

Linux

Prerequisite Topics

In order to understand and use the content on this page, make sure you are familiar with the following topics:

In the following example, we have a sample command that prints out a Fibonacci sequence of numbers before exiting successfully. Follow this example to add a new command (or script) to your automation project:

Steps

Required Step : Before continuing, make sure that there is an empty *.cs source file in the scope of your automation project.

  1. First, make sure to name your source file, and in our example, we named our file SimpleScript.cs .

  2. Now, copy the following sample code into your script:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using AutomationTool;
    
    namespace SampleScript.Automation
    {
        // Use [Help()] attributes to document your command and its arguments.
        [Help("Sample script printing a Fibonacci sequence of values.")]
        [Help("Usage: SampleScript -Terms=<N>")]
        [Help("Terms=<N>", "N (int) represents how many terms to compute, and it must be greater than or equal to 1.")]
    
        // BuildCommand is the base class for all commands.
        public class SampleCommand : BuildCommand
        {
            public override void ExecuteBuild()
            {
                // The ParseParamInt() method retrieves a command line argument for this example. ParseParam() retrieves a bool, and ParseParamValue retrieves a string.
                int NumTerms = ParseParamInt("Terms");
                if (NumTerms < 1)
                {
                    throw new AutomationException("Invalid number of terms specified. Enter -help for syntax.");
                }
                else
                {
                    LogInformation("Fibonnacci sequence:");
    
                    int TermA = 1;
                    int TermB = 1;
                    for (int TermIdx = 0; TermIdx < NumTerms; TermIdx++)
                    {
                        LogInformation("  {0}", TermA);
    
                        int NextTerm = TermA + TermB;
                        TermA = TermB;
                        TermB = NextTerm;
                    }
                }
            }
        }
    }
  3. Finally, open a Command Prompt, navigate to Engine\Build\BatchFiles , and enter RunUAT.bat SampleCommand -terms=4 .

End Result

You should see the following output:

AddingaCommand_EndResult.png

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss