Preface

Startup instructions are provided by software designers to provide some presets when starting the software in order to achieve the purpose of startup configuration. Startup instructions are somewhat similar to the input parameters of a function. Through startup instructions, the software can know some execution instructions when it starts to achieve the purpose of adjusting the software status.

Description

The startup instruction is essentially a text string. After starting the software, the text string is obtained and some parameter values ​​are obtained by parsing the string.

In Unreal Engine, there are two types of startup instructions for configuration: one is for service software and the other is for service games. The two are separate, so we will also talk about them separately.

Startup instructions (software)

The software-based startup instructions are more for adjusting some configurations when the software starts, such as language version, resolution, etc.

1. Instruction format

The following is a command string for starting an independent process in the Unreal Engine Editor:

/Game/NewMap -game -PIEVIACONSOLE -Multiprocess GameUserSettingsINI=PIEGameUserSettings0 -MultiprocessSaveConfig -forcepassthrough -messaging -SessionName="Play in Standalone Game" -windowed -ResX=1280 -ResY=720

Note: Use spaces as separators between instruction tags

Through analysis, we can probably get the instruction format rules as follows:

  • Boolean value: divided into prefixed minus sign and no prefix
  • With prefix, for example: -game
  • Without prefix, not in the sample, you can write it yourself, for example: OpenFair
  • Key value type: divided into prefixed minus sign and no prefix
  • With prefix, for example: -ResX=1280
  • Without prefix, for example: GameUserSettingsINI=PIEGameUserSettings0 (When parsing in the engine, key value tags without a minus sign prefix are treated as ordinary text strings, refer to [Parsing Instructions] (#3 Reading and Parsing Instructions) Parameter Description)
  • Path value: / content, for example: /Game/NewMap

**You can also design your own instruction markup format, but you need to write the parsing yourself (it is recommended to use the engine's rules). **

2. Configure instructions

Startup instruction configuration is divided into pre-packaging and post-packaging.

  • Configuration in development mode (can only be used for development, not after release), can be found in Editor Preferences-Playback, refer to the figure below.
    Configure in the editor
    Configure in the editor
  • Configure after packaging

a. Start the project through the console (CMD), add instructions (note that there is a space between the instruction and the project)

Start the project through the console
Start the project through the console
b. Create a shortcut and configure it in the shortcut
Create shortcut
Create shortcut
After creating the shortcut, right-click the property configuration and fill in the instruction in the shortcut target window (note the space)
Right-click shortcut property configuration
Right-click shortcut property configuration

3. Read and parse instructions

Read instructions: In the blueprint, you can use the node "GetCommandLine" to return the instruction string

Get startup instructions
Get startup instructions
Parse instructions: The blueprint provides a command parsing function
Parsing command function
Parsing command function
Parameter description:

  • In Cmd Line: Start command, usually obtained through "GetCommandLine"
  • Out Tokens: Returns all command tokens without a minus sign prefix in the command, such as: "/Game/NewMap", "GameUserSettingsINI=PIEGameUserSettings0", "OpenFair"
  • Out Switches: Returns non-key value type tokens with a minus sign in the command, such as: "game", "PIEVIACONSOLE", "Multiprocess", etc. Note that the return result does not have a minus sign.
  • Out Params: Returns the key value type token with a minus sign in the command, such as "-SessionName="Play in Standalone Game"" will be parsed as the key is "SessionName" and the value is "Play in Standalone Game"

There are also two node functions in the blueprint for parsing commands "Parse Param" and "Parse Param Value" can be used for function description.

Start Command (Game)

1. Add Command

Unreal Engine also allows you to append a command text when starting the game map. For example, to start the listening server, you need to add the suffix "listen". The adding location is as follows:

Game Command Configuration
Game Command Configuration

2. Read Command

Commands can be obtained in gamemode, as shown in the following screenshot:

Get Command
Get Command

3. Parse Command

The command string parsing method provided by the engine requires that the command mark in the command format use question marks as delimiters, such as "?listen=100?hero=122?np"

Of course, you can still write the format yourself, but the parsing also needs to be written by yourself. It is recommended to use the engine.

The parsing reference is as follows:

Parsing function
Parsing function

  • Options: command string
  • Key and In Key: key to be searched or parsed
  • The first node returns: 100
  • The second node returns: true

Conclusion

Just remember that the command is a text string. The engine provides two input methods for commands. As for the parsing method, the method provided by the engine needs to comply with the command format. If you want to design your own command parsing tag method, you can, but you need to write your own parsing method.

For use in C++, you can refer to the blueprint method to find the C++ source code.

Engine version: 5.2