I’ve been trying to find a way to add a version number to my application. I’d prefer if this number increments either every time a new commit is pushed, or whenever the game is built.
I’m aware there’s a Project Version (default 1.0.0.0) in the project settings, but as far as I understand, this has to be manually set.
I also looked at using GitVersion, but using that in my UE5 game does not seem to be its purpose.
I also found out there’s a BuildVersion which includes a BuildId you can read, but that seems to be for the engine version, not for the specific app.
I was thinking of maybe implementing a custom solution where a number increments every time the project is compiled or something similar. But maybe I’m missing a more obvious solution.
I was wondering how you guys have implemented this in the past. This would seem like a feature most games have, but I cannot seem to find a lot of information about it.
// needs at top
// #include "GeneralProjectSettings.h"
// i used a blueprintlibrary class as my base
void UYourCustomSettingClass::ChangeVersion(FString newVersion, float step) {
UGeneralProjectSettings* ProjectSettings = GetMutableDefault<UGeneralProjectSettings>();
if (newVersion == "") {
float lastVersion = FCString::Atof(*ProjectSettings->ProjectVersion);
lastVersion = lastVersion += 0.1;
newVersion = FString::SanitizeFloat(lastVersion);
}
ProjectSettings->ProjectVersion = newVersion;
ProjectSettings->SaveConfig();
}
in your build file you need to add the “EngineSettings” module
Not sure if unreal commands can be called from the command line. I’m not finding any human readable version parameters in the project structure that could be manipulated by external tools.
Good to know I can directly write directly to the built-in project version through code. But I’m still a bit unsure as to when to call this function.
Does the engine provide any sort of callback for when the project is built? Because this is the part I am a bit stuck on.
Looking through the internet I found that it’s possible to track when the project compiles in the MyProject.Target.cs file. But I’m guessing this would increment the counter only on compiles through visual studio (and would probably also increment on failed compiles) and not necessarily blueprint compilation (unsure about this though).
Incrementing it during a build would seem like the obvious solution, but even then two builds could be made without changing anything in the project which would result in 2 identical builds with differing project version.
Do you have any suggestions as to how you would approach this?
A simple file load / regex replace / file save function should be enough to change it.
You could write a small script to do this before upload in your language of choice.