Does UE have a build or version number system that is accessible in code

I would like access to a build ID or version number of my application from within C++. Does UE already have a system for that? I don’t need access to the version of Unreal, I want access to an internal build number.

Thanks

I had the same problem, so I threw this together in a few hours. Im sure there is a better way to do it, as this is my first time using batch.

Copy paste this into Build.bat in Engine/Build/BatchFiles/ right after the @echo off

IF EXIST "%~dp0\VersionNumbering.bat" (
	call "%~dp0\VersionNumbering.bat" %*
) ELSE (
	ECHO VersionNumbering.bat not found in %~dp0 
	EXIT /B 999
)

Then, make a file VersionNumbering.bat in the same folder:

@ECHO OFF

::Set var NEWTIME to the time, replacing colons with nothing
SET NEWTIME=%TIME::=% 

::Change new time, so that a space is replaced with 0
::ex: " 845" (8:45) becomes "0845".
:: if you want it to be "845": SET NEWTIME=%NEWTIME: =%
SET NEWTIME=%NEWTIME: =0%

::Deletes the Seconds and 10ths of seconds
SET NEWTIME=%NEWTIME:~0,-5%

::at this point, Variable NEWTIME is the time in the format hhmm

::Get the root directory of the project (where the .uproject and visual studio files are)
SET DIRECTORY=%~dp4

::if Directory has a trailing slash, remove it
IF %DIRECTORY:~-1%==\ SET DIRECTORY=%DIRECTORY:~0,-1%

::set SVNVERSION to be the output of svnversion (revision number)
FOR /f "delims=" %%a IN ('svnversion "%DIRECTORY%"') DO @SET SVNVERSION=%%a

:: directory path after DIRECTORY where the VersionNumber.h file will be placed (same directory as all the .generated.h files are)
SET DIRECTORYINCLUDE=\Intermediate\Build\%2\Inc\%~n4

:: svnversion sometimes outputs revision numbers with flags m or s, this removes those
:: ex 14:16MS -> 14:16
SET SVNVERSION=%SVNVERSION:M=%
SET SVNVERSION=%SVNVERSION:S=%

::This gets the second revision number (latest one)
:: ex 14:16 -> 16
FOR /F "tokens=2 delims=:" %%A IN ("%SVNVERSION%") DO SET OUTPUT=%%A

:: if there is only one revision number, OUTPUT will == "", so set Output to be the whole string
IF ""=="%OUTPUT%" SET OUTPUT=%SVNVERSION%

::STR generates the version number is the version number
:: format:       RevisionNumber . YY . MM . DD . HHMM
set "str=%OUTPUT%.%DATE:~12,2%.%date:~4,2%.%date:~7,2%.%NEWTIME%"

:: generates the full file path to where VersionNumber.h should be
SET FILEPATH=%DIRECTORY%%DIRECTORYINCLUDE%\VersionNumber.h

:: create VersionNumber (or overwrite the current one)
:: and then define VERSION_NUMBER in it
ECHO #define VERSION_NUMBER "%str%" > "%FILEPATH%"

:: output the version number to the build stream
ECHO Build Version Number: %str%

Use #include “VersionNumber.h” in your source file, and the version number will be defined as the VERSION_NUMBER macro.

Check : Engine\Source\Runtime\Launch\Resources\Version.h

#define ENGINE_MAJOR_VERSION 4
#define ENGINE_MINOR_VERSION 6
#define ENGINE_PATCH_VERSION 1

#define BUILT_FROM_CHANGELIST 2386410

Voilà,

1 Like

oh, I forgot to add, this is designed to work with svn, but it can be adjusted to work with other version control software (or none at all).