Although UE is a game engine, it is not limited to writing games—you can even use it to write Win32 GUI applications 😏. Typically, we create a UE game project using the Editor and build our own classes based on it for use in the game. However, if you don’t want to create a game project, UE also supports Standalone Applications that can construct their own programs autonomously from the main
function, fully controlling which Modules to enable without relying on the engine’s own logical architecture. This can also serve as a lightweight method for learning and testing UE modules.
Note: UE does not provide a direct method to create a Standalone Application, so I wrote a tool to create a
Program
project: hxhb/ue4program, and implemented a demo for a standalone tool: hxhb/UE4Launcher.
Forward
The content of this article requires using the engine built from source locally (source version engine) rather than the engine installed via EpicGameLauncher (installed version engine). In my previous articles, I introduced that UBT checks for the existence of the Engine/Build/InstalledBuild.txt
file to determine if the engine is installed from the Launcher or compiled from source. However, there are more differences between the source version and the installed version; some ThirdParty build.cs
files differ, leading to different compilation behaviors for the same code in source and installed version engines (for example, Engine/Source/ThirdParty/HarfBuzz
). Although these issues can be resolved, I do not recommend you do so.
Create Program
First, download my written hxhb/ue4program and add it to your system PATH. The usage after adding is as follows:
1 | # ue4program.exe ProgramName |
At this point, a StandaloneApplication
folder will be created in the current directory, with the following directory structure:
1 | StandaloneApplication |
This article focuses on analyzing the *.target.cs
and *.build.cs
files. After creating it, move the StandaloneApplication
folder to Engine\Source\Programs
, as all UE auxiliary programs (UHT/UBT, etc.) are under this directory. Then, run GenerateProgramProject.bat
; this is a script I wrote based on UE’s GenerateProjectFiles.bat
, which calls UBT to create the Standalone Application
program, with the command as follows:
1 | # bash path in Engine\Source\Programs\StandaloneApplication |
Note: Using the command above directly in the installed version of the engine will result in an error (creating non-Game projects is not allowed) because even though the -notinstallengine
parameter is passed, the detection priority for the Engine/Build/InstalledBuild.txt
file is higher than -notinstallengine
:
1 | Zhalipeng MINGW64 /d/UE_4.18/Engine/Source/Programs/StandaloneApplication (master) |
My script includes a check that, if the installed version of the engine is used, will first rename InstalledBuild.txt, and restore it after production (but I still recommend not executing this in the installed version engine). Once executed, it will generate the following in Engine\Intermediate\ProjectFiles
:
1 | StandaloneApplication.vcxproj |
This essentially adds the current project to the UE solution, and after execution, you can open the UE4.sln
file in the engine root directory to see the created project:
First, let’s compile and run to see the results:
Program *.target.cs
UBT supports several Target types (specified by the enum type TargetType):
- Game: Independently running game;
- Client: Same as Game, but does not contain any server code;
- Server: Same as Game, but does not contain any client code;
- Editor: Extension of the UE editor;
- Program: Independently running program;
1 | // Engine/Source/Programs/UnrealBuildTool/Configuration/TargetRules.cs |
For documentation on .target.cs
: UnrealBuildTool/Targets.
The generated *.target.cs
template from hxhb/ue4program:
1 | using UnrealBuildTool; |
Currently, the three main parameters to focus on are:
- Type: Specify as the target type to build
TargetType.Program
. - LinkType: Specify
TargetLinkType.Monolithic
to compile the target into a single executable file (not relying on any DLL). - bIsBuildingConsoleApplication:
true
supports Console, with the entry point beingmain
;false
does not support Console, with the entry point beingWinMain
.
Other parameters (RTTI/Exceptions) can be queried based on demand when used.
Program *.Build.cs
The *.Build.cs
of the Program does not differ from those of ordinary game projects because Game is a module and Program is also one; the only difference is in how these modules are built into target types (determined by *.target.cs
).
Demo: UELauncher
hxhb/UE4Launcher is a handy UE Project launcher I wrote using UE’s Program
mode, which conveniently allows adding launch parameters and selecting engine versions. You can download and install it from hxhb/UE4Launcher/release. I have a separate article introducing the tool, update logs, and download links: Open Source Unreal Engine Launcher UE Launcher.
Main interface:
Edit configuration files:
Right-click menu association for .uproject
files:
Right-click menu association for .uejson
files:
Command line parameter support:
-g
: The-g
parameter followed by the.uproject
file generates a.uejson
configuration file for it;-e
: The-e
parameter followed by a.uejson
file opens the window to edit that configuration file;-c
: The-c
parameter followed by a.uejson
file launches that configuration (without opening the edit window)
1 | # generate LauncherConf_ShooterGame.uejson |
The source code also supports very simple extensions to other UE tools, such as UBT
/AutomationTool
, which can all be added as tools to start (with Editor/Editor-cmd
as the default).
End
Using Slate to write UI can refer to various control usages in the SlateViewer
template example and can also draw on the implementation of UnrealFrontend
. Of course, Standalone Application
can do much more than just writing UI; all modules in UE can be used, making it a super powerful Library, and it is cross-platform. Explore more of its wonderful features gradually.