Skip to content

Instantly share code, notes, and snippets.

@Solessfir
Last active April 11, 2025 22:26
Show Gist options
  • Save Solessfir/8ed3df75b51214661131bc13dc9d05ee to your computer and use it in GitHub Desktop.
Save Solessfir/8ed3df75b51214661131bc13dc9d05ee to your computer and use it in GitHub Desktop.
Unreal Engine Derived Data Cache Builder
:: 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 Error: No .uproject file found in %RootDirectory% or its parent directory.
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 Error: Could not find custom engine executable in %CustomEngineDir%\Binaries\Win64.
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 Error: Couldn't find Unreal Engine installation for version !EngineVersion!.
echo Ensure Unreal Engine !EngineVersion! is installed via the Epic Games Launcher.
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 Error: Editor executable not found at !UnrealEditorPath!.
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 Error: Failed to build Derived Data Cache. Check the editor log for details.
) else (
echo Derived Data Cache built successfully.
)
:ExitWithPause
pause
exit /b 0
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment