Last active
February 16, 2026 13:20
-
-
Save Solessfir/0f7d5ed02be195db124bb5cc851229ed to your computer and use it in GitHub Desktop.
Cleans up an Unreal Engine project directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :: Copyright (c) Solessfir under MIT license | |
| :: This batch file cleans up an Unreal Engine project directory by deleting temporary files and cached shaders. | |
| :: It supports UE4, UE5, and custom Unreal Engine versions. | |
| :: Options: | |
| :: 1. Project Cleanup - Cleans project-specific folders and, for standard engines, engine-specific AppData folders. | |
| :: 2. Engine Settings Cleanup - Cleans engine settings in AppData (applies to standard engines only). | |
| :: 3. AppData Cleanup - Cleans all Unreal Engine-related folders in AppData. | |
| :: 0. Help - Displays detailed information about each option. | |
| @echo off | |
| title Unreal Engine Cleanup | |
| setlocal EnableDelayedExpansion | |
| :: Enable ANSI color support (required for Windows versions older than 10 build 1511) | |
| reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1 /f >nul 2>&1 | |
| :: Set root directory to the script's location | |
| set "RootDirectory=%~dp0" | |
| set "RootDirectory=%RootDirectory:~0,-1%" | |
| :: Locate the .uproject file | |
| for %%i in ("%RootDirectory%\*.uproject") do ( | |
| set "UprojectFilePath=%%~i" | |
| goto :UprojectLocationFound | |
| ) | |
| :: Look one directory up without changing the working directory | |
| for %%i in ("%RootDirectory%\..") do set "RootDirectory=%%~fi" | |
| for %%i in ("%RootDirectory%\*.uproject") do ( | |
| set "UprojectFilePath=%%~i" | |
| goto :UprojectLocationFound | |
| ) | |
| echo [91mError: No .uproject file found in %RootDirectory% or its parent directory.[0m | |
| goto :ExitWithPause | |
| :UprojectLocationFound | |
| :: Extract Engine version from .uproject file | |
| for /f "tokens=2 delims=: " %%a in ('findstr /i /c:"EngineAssociation" "%UprojectFilePath%"') do ( | |
| set "EngineVersion=%%a" | |
| set "EngineVersion=!EngineVersion:~1,-2!" | |
| ) | |
| :: Check for custom engine | |
| if "!EngineVersion!"=="" ( | |
| echo Custom engine detected. Skipping engine-specific AppData cleanup. | |
| echo: | |
| set "IsCustomEngine=1" | |
| ) else ( | |
| set "IsCustomEngine=0" | |
| :: Get major and minor version (e.g., 4.27) for standard engines | |
| for /f "tokens=1-2 delims=." %%a in ("!EngineVersion!") do ( | |
| set "EngineVersion=%%a.%%b" | |
| ) | |
| ) | |
| :: Extract project name | |
| for %%a in ("%UprojectFilePath%") do ( | |
| set "ProjectName=%%~na" | |
| ) | |
| :: Define IDE config directories | |
| set "RiderConfig=%RootDirectory%\.idea" | |
| set "VsConfig=%RootDirectory%\.vs" | |
| set "VscodeConfig=%RootDirectory%\.vscode" | |
| :Prompt | |
| echo [97mPlease enter an option from [92m1 [97mto [92m3[97m, or [92m0[97m for help:[0m | |
| echo: | |
| echo. [92m1[0m. Project Cleanup | |
| echo. [92m2[0m. Engine Settings Cleanup | |
| echo. [92m3[0m. AppData Cleanup | |
| echo: | |
| set /p UserInput="> " | |
| if "%UserInput%"=="0" goto :Help | |
| if "%UserInput%"=="1" goto :ProjectCleanup | |
| if "%UserInput%"=="2" goto :EngineSettingsCleanup | |
| if "%UserInput%"=="3" goto :AppDataCleanup | |
| echo Invalid input. Do you want to try again? (Y/N) | |
| set /p UserInput="> " | |
| if /i "%UserInput%"=="Y" goto :Prompt | |
| goto :DirectExit | |
| :Help | |
| cls | |
| echo [92m1. Project Cleanup[0m | |
| echo. What it does: Cleans up your project folder to free up space and remove unnecessary files. | |
| echo. What gets removed: | |
| echo. - Temporary folders like "Intermediate" and "Script" in your project directory. | |
| echo. - For Unreal Engine 4 or 5 (not custom engines), temporary files in AppData (e.g., user settings for that engine version). | |
| echo. - The entire "Binaries" folder. | |
| echo. - Most files in the "Saved" folder, except your collections and source control settings. | |
| echo. - Files from tools like Rider, Visual Studio, or VS Code, but keeps some settings (e.g., vcs.xml). | |
| echo. - Temporary plugin files (e.g., plugin "Binaries" and "Intermediate" folders). | |
| echo. Good for: When your project feels slow or takes up too much space. | |
| echo: | |
| echo [92m2. Engine Settings Cleanup[0m | |
| echo. What it does: Removes Unreal Engine settings stored on your computer, but only for standard engines (UE4/UE5). | |
| echo. What gets removed: | |
| echo. - The "UnrealHeaderTool" folder in AppData. | |
| echo. - Subfolders like "Collections," "Config," "Logs," etc., in AppData\UnrealEngine for all engine versions. | |
| echo. Good for: Resetting engine preferences or clearing logs without touching your project. | |
| echo: | |
| echo [92m3. AppData Cleanup[0m | |
| echo. What it does: Deletes all Unreal Engine-related data stored in AppData, including shaders and settings. | |
| echo. What gets removed: | |
| echo. - Everything in AppData\UnrealEngine (all engine versions). | |
| echo. - Everything in AppData\Unreal Engine (global settings). | |
| echo. - The "UnrealHeaderTool" folder. | |
| echo. Good for: A full reset of Unreal Engine data on your computer (e.g., if shaders are broken or you're troubleshooting). | |
| echo: | |
| echo Press any key to return to the main menu. | |
| pause >nul | |
| cls | |
| goto :Prompt | |
| :ProjectCleanup | |
| cls | |
| :: Delete project-specific folders | |
| set "project_folders=Intermediate Script" | |
| for %%f in (%project_folders%) do ( | |
| if exist "%RootDirectory%\%%f" ( | |
| echo Deleting folder %RootDirectory%\%%f | |
| rd /s /q "%RootDirectory%\%%f" | |
| ) | |
| ) | |
| :: Delete engine-specific AppData folders (standard engines only) | |
| set "appdata_folders=Config Intermediate" | |
| if "!IsCustomEngine!"=="0" ( | |
| for %%f in (%appdata_folders%) do ( | |
| if exist "%localappdata%\UnrealEngine\%EngineVersion%\%%f" ( | |
| echo Deleting folder %localappdata%\UnrealEngine\%EngineVersion%\%%f | |
| rd /s /q "%localappdata%\UnrealEngine\%EngineVersion%\%%f" | |
| ) | |
| ) | |
| if exist "%localappdata%\UnrealBuildTool" ( | |
| echo Deleting folder %localappdata%\UnrealBuildTool | |
| rd /s /q "%localappdata%\UnrealBuildTool" | |
| ) | |
| ) | |
| :: Clean Saved folder, preserving Collections subfolder and SourceControlSettings.ini | |
| :: Back up SourceControlSettings.ini before deleting anything | |
| set "TempSCS=%temp%\UE_SCS_backup.ini" | |
| set "SCSDir=" | |
| for /r "%RootDirectory%\Saved" %%f in (SourceControlSettings.ini) do ( | |
| if "!SCSDir!"=="" ( | |
| copy /y "%%f" "%TempSCS%" >nul 2>&1 | |
| set "SCSDir=%%~dpf" | |
| ) | |
| ) | |
| :: Delete all Saved subfolders except Collections | |
| for /d %%d in ("%RootDirectory%\Saved\*") do ( | |
| if /i not "%%~nd"=="Collections" ( | |
| echo Deleting folder %%d | |
| rd /s /q "%%d" | |
| ) | |
| ) | |
| :: Delete any loose files directly in the Saved root | |
| for %%f in ("%RootDirectory%\Saved\*") do ( | |
| echo Deleting file %%f | |
| del /f /q "%%f" | |
| ) | |
| :: Restore SourceControlSettings.ini to its original location | |
| if not "!SCSDir!"=="" ( | |
| if not exist "!SCSDir!" md "!SCSDir!" | |
| copy /y "%TempSCS%" "!SCSDir!SourceControlSettings.ini" >nul 2>&1 | |
| del /f /q "%TempSCS%" | |
| echo Preserving: !SCSDir!SourceControlSettings.ini | |
| ) | |
| :: Delete Binaries folder | |
| if exist "%RootDirectory%\Binaries" ( | |
| echo Deleting folder %RootDirectory%\Binaries | |
| rd /s /q "%RootDirectory%\Binaries" | |
| ) | |
| :: Clean IDE-specific files if config folders exist | |
| if exist "%RiderConfig%" ( | |
| for /r "%RiderConfig%" %%f in (*) do ( | |
| set "file=%%~nxf" | |
| if /i not "!file!"=="vcs.xml" if /i not "!file!"=="workspace.xml" ( | |
| echo Deleting file %%f | |
| del "%%f" >nul 2>&1 | |
| ) | |
| ) | |
| ) | |
| if exist "%VsConfig%" ( | |
| echo Deleting folder %VsConfig% | |
| rd /s /q "%VsConfig%" | |
| ) | |
| if exist "%VscodeConfig%" ( | |
| echo Deleting folder %VscodeConfig% | |
| rd /s /q "%VscodeConfig%" | |
| ) | |
| :: Delete additional IDE files | |
| set "ide_files=%RootDirectory%\%ProjectName%.uproject.DotSettings.user %RootDirectory%\%ProjectName%.sln %RootDirectory%\.vsconfig %RootDirectory%\%ProjectName%.code-workspace" | |
| for %%f in (%ide_files%) do ( | |
| if exist "%%f" ( | |
| echo Deleting file %%f | |
| del /f /q "%%f" | |
| ) | |
| ) | |
| :: Clean Plugins subfolders | |
| for /d /r "%RootDirectory%\Plugins" %%d in (*) do ( | |
| if "%%~nd"=="Binaries" ( | |
| echo Deleting plugin folder %%d | |
| rd /s /q "%%d" | |
| ) else if "%%~nd"=="Intermediate" ( | |
| echo Deleting plugin folder %%d | |
| rd /s /q "%%d" | |
| ) | |
| ) | |
| echo [92m%ProjectName% cleanup successfully completed.[0m | |
| echo: | |
| goto :ExitWithPause | |
| :EngineSettingsCleanup | |
| cls | |
| if "!IsCustomEngine!"=="1" ( | |
| echo [91mEngine Settings Cleanup is not supported for custom engines.[0m | |
| echo: | |
| goto :ExitWithPause | |
| ) | |
| if exist "%localappdata%\UnrealHeaderTool" ( | |
| echo Deleting folder %localappdata%\UnrealHeaderTool | |
| rd /s /q "%localappdata%\UnrealHeaderTool" | |
| ) | |
| set "subfolders=Collections Config Logs Content Intermediate Saved" | |
| for /d %%d in ("%localappdata%\UnrealEngine\*") do ( | |
| for %%s in (%subfolders%) do ( | |
| if exist "%%d\%%s" ( | |
| echo Deleting folder %%d\%%s | |
| rd /s /q "%%d\%%s" | |
| ) | |
| ) | |
| ) | |
| echo: | |
| echo [92mEngine Settings cleanup successfully completed.[0m | |
| echo: | |
| goto :ExitWithPause | |
| :AppDataCleanup | |
| cls | |
| if exist "%localappdata%\UnrealEngine" ( | |
| echo Deleting folder %localappdata%\UnrealEngine | |
| rd /s /q "%localappdata%\UnrealEngine" | |
| ) | |
| if exist "%appdata%\Unreal Engine" ( | |
| echo Deleting folder %appdata%\Unreal Engine | |
| rd /s /q "%appdata%\Unreal Engine" | |
| ) | |
| if exist "%localappdata%\UnrealHeaderTool" ( | |
| echo Deleting folder %localappdata%\UnrealHeaderTool | |
| rd /s /q "%localappdata%\UnrealHeaderTool" | |
| ) | |
| echo: | |
| echo [92mAppData cleanup successfully completed.[0m | |
| echo: | |
| goto :ExitWithPause | |
| :ExitWithPause | |
| pause | |
| exit /b 0 | |
| :DirectExit | |
| exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment