Skip to content

Instantly share code, notes, and snippets.

@alfredbaudisch
Last active March 2, 2024 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredbaudisch/11c2f2c13402b9f524398b7bd54885c9 to your computer and use it in GitHub Desktop.
Save alfredbaudisch/11c2f2c13402b9f524398b7bd54885c9 to your computer and use it in GitHub Desktop.
Unreal Engine Run Counter from the Editor (to keep track of how many times you run/launch/playtest the game during development)
#include "Core/YourGameInstance.h"
void UYourGameInstance::Init()
{
Super::Init();
// Do stuff..
#if WITH_EDITOR
FString FilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir()) + TEXT("/GameLaunches.txt");
FString LoadedFile;
FFileHelper::LoadFileToString(LoadedFile, *FilePath);
int32 GameLaunches = 1;
if (!LoadedFile.IsEmpty())
{
GameLaunches = FCString::Atoi(*LoadedFile) + 1;
}
LoadedFile = FString::FromInt(GameLaunches);
FFileHelper::SaveStringToFile(LoadedFile, *FilePath, FFileHelper::EEncodingOptions::AutoDetect,
&IFileManager::Get(), EFileWrite::FILEWRITE_None);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment