Last active
April 11, 2025 22:26
-
-
Save Solessfir/8ed3df75b51214661131bc13dc9d05ee to your computer and use it in GitHub Desktop.
Unreal Engine Derived Data Cache Builder
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 builds the Derived Data Cache (DDC) for an Unreal Engine project. | |
:: It supports UE4, UE5, and custom engine setups. | |
:: Place this file in your project's root directory and run it. | |
@echo off | |
title Build Derived Data Cache | |
setlocal EnableDelayedExpansion | |
:: Set root directory to the script's location | |
set "RootDirectory=%~dp0" | |
set "RootDirectory=%RootDirectory:~0,-1%" | |
:: Locate the .uproject file in the current or parent directory | |
for %%i in ("%RootDirectory%\*.uproject") do ( | |
set "UprojectFilePath=%%~i" | |
goto :UprojectLocationFound | |
) | |
cd .. | |
set "RootDirectory=%cd%" | |
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 | |
echo Found .uproject file: %UprojectFilePath% | |
:: Extract EngineAssociation from the .uproject file | |
for /f "tokens=2 delims=: " %%a in ('findstr /i /c:"EngineAssociation" "%UprojectFilePath%"') do ( | |
set "EngineAssociation=%%a" | |
set "EngineAssociation=!EngineAssociation:~1,-2!" | |
) | |
:: Check for custom engine (empty EngineAssociation) | |
if "!EngineAssociation!"=="" ( | |
echo Custom engine detected. | |
:: Assume custom engine is located in ..\Engine relative to the project | |
set "CustomEngineDir=%RootDirectory%\..\Engine" | |
:: Check for UE4Editor-Cmd.exe (UE4) or UnrealEditor-Cmd.exe (UE5) | |
if exist "%CustomEngineDir%\Binaries\Win64\UE4Editor-Cmd.exe" ( | |
set "UnrealEditor=UE4Editor-Cmd.exe" | |
set "UnrealEditorPath=%CustomEngineDir%\Binaries\Win64\UE4Editor-Cmd.exe" | |
) else if exist "%CustomEngineDir%\Binaries\Win64\UnrealEditor-Cmd.exe" ( | |
set "UnrealEditor=UnrealEditor-Cmd.exe" | |
set "UnrealEditorPath=%CustomEngineDir%\Binaries\Win64\UnrealEditor-Cmd.exe" | |
) else ( | |
echo [91mError: Could not find custom engine executable in %CustomEngineDir%\Binaries\Win64.[0m | |
goto :ExitWithPause | |
) | |
) else ( | |
:: Truncate to major.minor version (e.g., 4.27.2 -> 4.27) | |
for /f "tokens=1-2 delims=." %%a in ("!EngineAssociation!") do ( | |
set "EngineVersion=%%a.%%b" | |
) | |
echo Using Engine Version: !EngineVersion! | |
:: Query registry for Unreal Engine installation directory | |
set "EngineDirectory=" | |
for /f "skip=2 tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\EpicGames\Unreal Engine\!EngineVersion!" /v "InstalledDirectory" 2^>nul') do ( | |
set "EngineDirectory=%%b" | |
) | |
if not defined EngineDirectory ( | |
echo [91mError: Couldn't find Unreal Engine installation for version !EngineVersion!.[0m | |
echo [93mEnsure Unreal Engine !EngineVersion! is installed via the Epic Games Launcher.[0m | |
goto :ExitWithPause | |
) | |
:: Determine the editor executable based on engine version | |
if "!EngineVersion:~0,1!"=="4" ( | |
set "UnrealEditor=UE4Editor-Cmd.exe" | |
) else ( | |
set "UnrealEditor=UnrealEditor-Cmd.exe" | |
) | |
set "UnrealEditorPath=!EngineDirectory!\Engine\Binaries\Win64\!UnrealEditor!" | |
) | |
:: Check if the editor executable exists | |
if not exist "!UnrealEditorPath!" ( | |
echo [91mError: Editor executable not found at !UnrealEditorPath!.[0m | |
goto :ExitWithPause | |
) | |
echo Unreal Editor Path: !UnrealEditorPath! | |
echo: | |
:: Run the command to build the Derived Data Cache | |
echo Building Derived Data Cache... | |
call "!UnrealEditorPath!" "!UprojectFilePath!" -run=DerivedDataCache -fill -DDC=CreatePak -ProjectOnly | |
:: Check if the build was successful | |
if !errorlevel! neq 0 ( | |
echo [91mError: Failed to build Derived Data Cache. Check the editor log for details.[0m | |
) else ( | |
echo [92mDerived Data Cache built successfully.[0m | |
) | |
:ExitWithPause | |
pause | |
exit /b 0 | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment