Unreal Engine Linux support has slowly been getting more and more functional. The biggest sticking point I have always come across is the inability to build from the command line and have that build reliably produce a hot-reload library that the Unreal Editor will use.

After trying a few different things and finding some help on the forums, I have come up with a method to reliably build both the hot-reload module and entire game project.

These methods have only been tested on Unreal Engine v4.21.2, if trying to use them on other versions your mileage may vary.

To build a game project using Linux, I have found the most reliable way to be with using the Unreal Build Tool directly. Since this is a windows executable, you’ll have to source the SetupMono.sh script from Unreal Engine to be able to call UnrealBuildTool.exe. This post on the UE4 AnswerHub really helped me out while looking for a solution.

[code lang=”bash” gutter=”false”] function prepare-ue4-ubt { # Prepare Unreal Build Tool source ${UE_HOME}/Engine/Build/BatchFiles/Linux/SetupMono.sh ${UE_HOME}/Engine/Build/BatchFiles/Linux xbuild /property:Configuration=Development /property:TargetFrameworkVersion=v4.5 /verbosity:quiet /nologo ${UE_HOME}/Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool.csproj } [/code]

Now that we can run the Unreal Build Tool directly, building the shared library used by the Unreal Editor for hot-reloading gameplay code isn’t that difficult. Simply generate a random number in the range [1000, 1999], specify the type of build, and away we go.

[code lang=”bash” gutter=”false”] function uebuild-hotreload { # Setup RANDNUM=$(( ( RANDOM % 1000 ) + 1000 )); CURR_DIR=`pwd`; PROJ_NAME=$(basename ${1%.uproject}); PROJ_NAME_MODULE=”${PROJ_NAME},${RANDNUM}”; prepare-ue4-ubt # Build project hot reload module mono ${UE_HOME}/Engine/Binaries/DotNET/UnrealBuildTool.exe -ModuleWithSuffix=$PROJ_NAME_MODULE Linux Development -TargetType=Editor -Project=”${CURR_DIR}/${PROJ_NAME}.uproject” -canskiplink “${CURR_DIR}/${PROJ_NAME}.uproject” -progress -editor -game } complete -f -X ‘!*.@(uproject)’ uebuild-hotreload [/code]

On rare occasion I have found building this way to cause issues. Since it doesn’t go through the process of linking the entire game project there is a chance you can introduce linker errors at that level and be unaware of them for some time. The extent to which those errors will cause you grief depends on how long it has been since they were introduced.

The best way I have found to always reliably build from the command line and find all the issues that my code might have made is to build in two steps.

First, I build the game project as a whole to make sure there are no linker issues.

[code lang=”bash” gutter=”false”] function uebuild-no-hotreload { # Setup CURR_DIR=`pwd`; PROJ_NAME=$(basename ${1%.uproject}); prepare-ue4-ubt # Build entire project mono ${UE_HOME}/Engine/Binaries/DotNET/UnrealBuildTool.exe $PROJ_NAME Linux Development -editorrecompile -Project=”${CURR_DIR}/${PROJ_NAME}.uproject” -progress -editor – } complete -f -X ‘!*.@(uproject)’ uebuild-no-hotreload [/code]

Second, I build the hot-reload module to tell the Unreal Editor that there is new code it should be loading.

Using the combination of these two steps, I have found that I can reliably catch all errors that may have been introduced by my code and I can produce a hot-reload module that the editor will happily use.

The one down side to this method is that you end up building most of the same code twice which is slower than ideal. I haven’t yet gone digging through how UBT performs linking, but I imagine there is a way to bypass the second build step by simply re-linking with different target parameters.

Anyway, I hope this may be helpful to others trying to build on Linux. Send me a message if you know of other/better ways to accomplish what I am trying to do.

Leave a Reply