Getting the exact build or “Package & Cook” date of your game directly using built-in functions or variables isn’t straightforward if you are using the precompiled binaries of the engine (as it sounds like you are). This is primarily because, as you noted, the FApp::GetBuildDate()
function returns the build date of the engine itself, not of your specific project or its cooking session.
There is a couple of options you can try…
1. Automation Scripting
One common approach is to use Unreal Engine’s automation tools (like Unreal Build Tool or UBT) and scripting to generate a build timestamp during the cook and package process. You can write a simple script that runs as part of your build process, which writes the current date and time to a file or directly into a code file as a static variable.
For example, you can add a step in your build pipeline (using a batch file, shell script, or custom build step in your IDE) that writes the current build timestamp to a config file or directly into a header file that your Unreal project can read from.
2. Pre-Build Events
Use pre-build events in your project’s build configuration to execute a command line script that will generate a header file or update a configuration file with the current date and time. Here’s a simple example using a batch file for a Windows build:
echo #define BUILD_TIMESTAMP "%DATE% %TIME%" > Config/BuildTimestamp.h
Then, in your game code, you can include BuildTimestamp.h
and use the BUILD_TIMESTAMP
macro where needed.
3. Blueprints
If you prefer not to involve C++ and are working mostly in Blueprints, you can create a custom Blueprint node using a C++ function that reads the system date and time at runtime and formats it as a string. This won’t give you the build date but the date when the game was launched, which might still be useful depending on your needs.
4. Third-Party Tools
Consider using third-party build automation tools like Jenkins, TeamCity, or GitLab CI/CD, which can automate the process of injecting build timestamps into your game files. These tools can set environment variables or modify game files at build time, which your game can then access to display the build date.
5. Post-Build Tools
After the build, use a custom tool to modify the packaged game’s files. For example, a simple tool could modify a JSON or XML file inside the packaged game’s content folder with the current date and time after the build completes.
Implementation in C++
If you decide to use a C++ approach, you could add a static class or namespace in your game’s source code that holds the build timestamp:
namespace BuildInfo
{
static const FString BuildTimestamp = TEXT("Build timestamp not set");
}
And during the build process, overwrite this file or variable with the current timestamp.
Hope this helps.