Incremental Product Version to display in-game to the user

Searching is being problematic. Because there are so many different types of ‘versions’ at play.

I am trying to have a simple in-game displayable ‘build version count’ to display in the corner while someone is playing the game.

This has nothing to do with compatibility or anything. And I want it to increment with every build.

There is a lot of conflation with unreal engine’s blueprint asset version, build version, or compatibility version or other things, but most of those aren’t what. I just want a user showable thing that increments with every build.

I have 2-3 solutions that ‘technically work’ but feel SUPER hacky. Anyone have any good suggestions or tips?

Bonus: Would be also having a ‘build time stamp’ that is readable on UI in game. e.g. YY-MM-DD-HH
Bonus: Something that doesn’t touch cpp/header files that can trigger unnecessary rebuilds.

I ended up finding a decent solution on the unreal slackers discord

public static void IncrementGameVersion(string ProjectRootPath)
	{
		string gameIniPath = Path.GetFullPath(Path.Combine(ProjectRootPath, "Config", "DefaultGame.ini"));
		bool bFileExists = File.Exists(gameIniPath);

		if (!bFileExists)
		{
			System.Console.WriteLine($"ERROR: Can't find DefaultGame.ini at {gameIniPath}");
			return;
		}


		string projectVersionName = "ProjectVersion";
		string projectVersionNameLower = projectVersionName.ToLower();

		bool bFoundLine = false;
		string[] lines = File.ReadAllLines(gameIniPath);
		string newVersion = "1.0.0.0";

		for (int i = 0; i < lines.Length; i++)
		{
			if (lines[i].ToLower().StartsWith(projectVersionNameLower))
			{
				bFoundLine = true;
				string oldVersion = lines[i].Split("=")[1];
				string[] oldVersionSplit = oldVersion.Split(".");

				string Major = oldVersionSplit[0];
				string Minor = oldVersionSplit[1];
				string Patch = oldVersionSplit[2];
				UInt32 Build = UInt32.Parse(oldVersionSplit[3]);
				Build += 1;
				newVersion = Major + "." + Minor + "." + Patch + "." + Build;
				lines[i] = projectVersionName + "=" + newVersion;
				break;
			}
		}

		if (bFoundLine)
		{
			File.WriteAllLines(gameIniPath, lines);
			System.Console.WriteLine("New game version: " + newVersion);
		}
		else
		{
			System.Console.WriteLine($"ERROR: {projectVersionName} Not found in DefaultGame.ini at {gameIniPath}");
		}
	}

That function above is called in my Target.cs file
IncrementGameVersion(ProjectFile?.Directory.ToString());

then insides the game I can do

FString ProductVersion;
	if (GConfig->GetString(
		TEXT("/Script/EngineSettings.GeneralProjectSettings"),
		TEXT("ProjectVersion"),
		ProductVersion,
		GGameIni
	)) {
		return ProductVersion;
	}

This also works for a custom BuildInfo.ini and BuildDate I added similiarally as above but in other ini files.

1 Like

Hi,
I know it’s been a long time ago, but I’m just looking for exact solution. But… I don’t know C#, just C++.
I know what everyone will say now, that C# is easier and how I can’t understand it while knowing C++ :frowning: I tried… many times. I’m writing in C++ for years, but C# is just black magic for me. So…
I pasted your code into my ProjectName.Target.cs (this is UE5.5 project) and this what happened:


Can you please tell me, like for the complete noob, where I suppose to paste it and how to use it later?

For exchange, here’s my solution for getting the game version. It’s almost the same, but adding compilation configuration at the end.

FString USomeClassMaybeWidget::GetVersion() const {
	FString sVer;
	GConfig->GetString(TEXT("/Script/EngineSettings.GeneralProjectSettings"), TEXT("ProjectVersion"), sVer, GGameIni);
#if UE_BUILD_DEBUG
	sVer += TEXT(" Debug");
#endif
#if UE_BUILD_DEVELOPMENT
	sVer += TEXT(" Development");
#endif
#if UE_BUILD_TEST
	sVer += TEXT(" Test");
#endif
	return sVer;
}