Adding Commands

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

Windows
MacOS
Linux
필요한 사전지식

이 글은 다음 주제에 대한 지식이 있는 분들을 대상으로 합니다. 계속하기 전 확인해 주세요.

목차

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

언리얼 엔진 문서의 미래를 함께 만들어주세요! 더 나은 서비스를 제공할 수 있도록 문서 사용에 대한 피드백을 주세요.
설문조사에 참여해 주세요
건너뛰기