Skip to content

Instantly share code, notes, and snippets.

@AaronTrotter
Last active May 23, 2024 20:23
Show Gist options
  • Save AaronTrotter/dc8cce655c6a61d77826290c40b7e313 to your computer and use it in GitHub Desktop.
Save AaronTrotter/dc8cce655c6a61d77826290c40b7e313 to your computer and use it in GitHub Desktop.
Clear UE5 binaries, intermediate of project and plugins and regenerates project files
param (
[string]$UProjectPath
)
function Remove-Directory {
param (
[string]$Path
)
if (Test-Path $Path) {
Write-Output "----cleared $Path"
Remove-Item -Recurse -Force $Path -ErrorAction SilentlyContinue
}
}
function Get-EnginePath {
param (
[string]$EngineAssociation
)
$registryPath = "HKLM:\SOFTWARE\EpicGames\Unreal Engine\$EngineAssociation"
$enginePath = Get-ItemProperty -Path $registryPath -Name "InstalledDirectory" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty InstalledDirectory
if (-not $enginePath) {
throw "Engine path not found for EngineAssociation: $EngineAssociation"
}
return $enginePath
}
function Get-EngineAssociation {
param (
[string]$UProjectFile
)
$uprojectContent = Get-Content -Path $UProjectFile -Raw | ConvertFrom-Json
return $uprojectContent.EngineAssociation
}
$dt = Get-Date -Format "yyyy.MM.dd-HH.mm.ss"
$projectPath = ""
$projectName = ""
$ID = 0
$filename = @()
Write-Output "removing cache"
Write-Output "--searching root"
Remove-Directory -Path "Binaries"
Remove-Directory -Path "Intermediate"
Get-ChildItem -Directory "Plugins" | ForEach-Object {
Write-Output "--searching $($_.FullName)"
Remove-Directory -Path "$($_.FullName)\Binaries"
Remove-Directory -Path "$($_.FullName)\Intermediate"
}
Write-Output "searching root for UProject"
$uprojects = Get-ChildItem -Filter *.uproject -Name
if ($uprojects.Count -eq 0) {
Write-Output "No .uproject files found."
Exit
}
foreach ($uproject in $uprojects) {
$filename += $uproject
$ID++
$projectName = $uproject
$projectPath = Join-Path -Path $PWD -ChildPath $uproject
}
Write-Output "--$ID UProject(s) Found"
$logPath = Join-Path -Path $PWD -ChildPath "Saved\Logs\UnrealVersionSelector-$dt.log"
try {
$engineAssociation = Get-EngineAssociation -UProjectFile $projectPath
$enginePath = Get-EnginePath -EngineAssociation $engineAssociation
Write-Output "Engine Found: $enginePath"
$buildToolPath = Join-Path -Path $enginePath -ChildPath "Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.exe"
if ($ID -gt 0) {
Write-Output "--rebuilding $projectName"
Write-Output "buildToolPath: $buildToolPath"
Write-Output "logPath: $logPath"
Start-Process -FilePath $buildToolPath -ArgumentList "-projectfiles", "-project=$projectPath", "-game", "-rocket", "-progress", "-log=$logPath"
}
} catch {
Write-Output $_.Exception.Message
}
Start-Sleep -Seconds 10
Exit
@AaronTrotter
Copy link
Author

AaronTrotter commented May 18, 2020

-- edit: This comment is for legacy bat file

Place this in root directory.
It will ask you for the engine path once. This is required to regenerate Visual Studio project. It will create a file called UE4ClearCacheEnginePath in the root directory. Exclude it from git.

@AaronTrotter
Copy link
Author

Place this in root directory.
Run with powershell. It will find the install location from the registry using the engine version in the project.

-> works with any UE5 version
-> Clears binaries and intermediate of project
-> Clears binaries and intermediate of plugins
-> Regenerates project files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment