Skip to content

Instantly share code, notes, and snippets.

@geekrelief
Created January 30, 2026 02:43
Show Gist options
  • Select an option

  • Save geekrelief/b73a30c821f1cf2289de568e0c81dbfc to your computer and use it in GitHub Desktop.

Select an option

Save geekrelief/b73a30c821f1cf2289de568e0c81dbfc to your computer and use it in GitHub Desktop.
Clean Intellisense for Unreal Visual Studio projects
# Save as Clean-UnrealIntelliSense.ps1
param(
[Parameter(Mandatory=$false)]
[string]$UProjectPath,
[Parameter(Mandatory=$false)]
[switch]$DryRun,
[Parameter(Mandatory=$false)]
[Alias("h")]
[switch]$Help
)
function Show-Help {
Write-Host @"
Clean-UnrealIntelliSense.ps1 - Clean Visual Studio IntelliSense and regenerate Unreal project files
USAGE:
.\Clean-UnrealIntelliSense.ps1 -UProjectPath <path> [-DryRun] [-Help]
PARAMETERS:
-UProjectPath <path> Path to your .uproject file (required)
-DryRun Show what would happen without making changes
-Help, -h Display this help message
EXAMPLES:
# Normal run (makes changes):
.\Clean-UnrealIntelliSense.ps1 -UProjectPath "C:\MyProjects\MyGame\MyGame.uproject"
# Dry run (preview changes):
.\Clean-UnrealIntelliSense.ps1 -UProjectPath "C:\MyProjects\MyGame\MyGame.uproject" -DryRun
# Show help:
.\Clean-UnrealIntelliSense.ps1 -Help
DESCRIPTION:
This script fixes Visual Studio IntelliSense issues by:
1. Closing Visual Studio if open
2. Deleting Browse.VC.db and ipch cache files
3. Regenerating Visual Studio project files from the .uproject
Common use case: Red squiggles and missing type definitions after adding new files/headers.
"@ -ForegroundColor Cyan
}
# Show help if no arguments provided or if -Help is specified
if ($Help -or (-not $PSBoundParameters.Count)) {
Show-Help
exit 0
}
if (-not $UProjectPath) {
Write-Error "Missing required parameter: -UProjectPath"
Write-Host "`nUse -Help for usage information`n" -ForegroundColor Yellow
exit 1
}
# Validate the .uproject file exists
if (-not (Test-Path $UProjectPath)) {
Write-Error "Project file not found: $UProjectPath"
exit 1
}
$projectDir = Split-Path -Parent $UProjectPath
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($UProjectPath)
if ($DryRun) {
Write-Host "=== DRY RUN MODE ===" -ForegroundColor Magenta
Write-Host "No changes will be made. Showing what would happen...`n" -ForegroundColor Magenta
}
Write-Host "Cleaning IntelliSense data for: $projectName" -ForegroundColor Cyan
# Close Visual Studio if it's running for this project
$vsProcesses = Get-Process devenv -ErrorAction SilentlyContinue | Where-Object {
$_.MainWindowTitle -like "*$projectName*"
}
if ($vsProcesses) {
if ($DryRun) {
Write-Host "[DRY RUN] Would close Visual Studio processes:" -ForegroundColor Yellow
$vsProcesses | ForEach-Object {
Write-Host " - PID $($_.Id): $($_.MainWindowTitle)" -ForegroundColor Gray
}
} else {
Write-Host "Closing Visual Studio..." -ForegroundColor Yellow
$vsProcesses | ForEach-Object { $_.CloseMainWindow() | Out-Null }
Start-Sleep -Seconds 2
$vsProcesses | Where-Object { -not $_.HasExited } | Stop-Process -Force
}
}
# Remove IntelliSense cache files
$vsFolder = Join-Path $projectDir ".vs"
if (Test-Path $vsFolder) {
if ($DryRun) {
Write-Host "[DRY RUN] Would clean .vs folder..." -ForegroundColor Yellow
} else {
Write-Host "Cleaning .vs folder..." -ForegroundColor Yellow
}
# Remove Browse.VC.db
$dbFiles = Get-ChildItem -Path $vsFolder -Recurse -Filter "Browse.VC.db*" -ErrorAction SilentlyContinue
if ($dbFiles) {
foreach ($file in $dbFiles) {
if ($DryRun) {
Write-Host " [DRY RUN] Would remove: $($file.FullName)" -ForegroundColor Gray
} else {
Write-Host " Removing: $($file.FullName)"
Remove-Item $file.FullName -Force -ErrorAction SilentlyContinue
}
}
} else {
Write-Host " No Browse.VC.db files found" -ForegroundColor Gray
}
# Remove ipch folder
$ipchFolders = Get-ChildItem -Path $vsFolder -Recurse -Directory -Filter "ipch" -ErrorAction SilentlyContinue
if ($ipchFolders) {
foreach ($folder in $ipchFolders) {
if ($DryRun) {
Write-Host " [DRY RUN] Would remove: $($folder.FullName)" -ForegroundColor Gray
# Show size
$size = (Get-ChildItem -Path $folder.FullName -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
if ($size) {
$sizeMB = [math]::Round($size / 1MB, 2)
Write-Host " (Size: $sizeMB MB)" -ForegroundColor DarkGray
}
} else {
Write-Host " Removing: $($folder.FullName)"
Remove-Item $folder.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
}
} else {
Write-Host " No ipch folders found" -ForegroundColor Gray
}
} else {
Write-Host ".vs folder not found (nothing to clean)" -ForegroundColor Gray
}
# Find Unreal Engine installation
$enginePath = $null
# Try to find engine path from .uproject file
$uprojectContent = Get-Content $UProjectPath -Raw | ConvertFrom-Json
if ($uprojectContent.EngineAssociation) {
$engineAssoc = $uprojectContent.EngineAssociation
Write-Host "Engine Association: $engineAssoc" -ForegroundColor Gray
# Check registry for custom engine builds (source builds have GUIDs)
$regPath = "Registry::HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Builds"
if (Test-Path $regPath) {
try {
$regKey = Get-Item -LiteralPath $regPath
$enginePath = $regKey.GetValue($engineAssoc)
if ($enginePath -and (Test-Path $enginePath)) {
Write-Host "Found engine in registry (custom build): $enginePath" -ForegroundColor Gray
} else {
$enginePath = $null
}
} catch {
# Registry key doesn't have this association
$enginePath = $null
}
}
# Check for launcher versions (format like "5.3" or "5.4")
if (-not $enginePath) {
# Get launcher install location from registry
$launcherRegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\EpicGames\Unreal Engine\$engineAssoc"
if (Test-Path $launcherRegPath) {
try {
$regKey = Get-Item -LiteralPath $launcherRegPath
$enginePath = $regKey.GetValue("InstalledDirectory")
if ($enginePath -and (Test-Path $enginePath)) {
Write-Host "Found engine in registry (launcher): $enginePath" -ForegroundColor Gray
} else {
$enginePath = $null
}
} catch {
$enginePath = $null
}
}
}
}
if (-not $enginePath) {
Write-Error "Could not find Unreal Engine installation for association '$engineAssoc'. Please verify the engine is installed."
exit 1
}
Write-Host "Using Unreal Engine at: $enginePath" -ForegroundColor Green
# Regenerate project files
$buildBat = Join-Path $enginePath "Engine\Build\BatchFiles\Build.bat"
if (-not (Test-Path $buildBat)) {
Write-Error "Build.bat not found at: $buildBat"
exit 1
}
if ($DryRun) {
Write-Host "[DRY RUN] Would regenerate Visual Studio project files using:" -ForegroundColor Yellow
Write-Host " Command: $buildBat" -ForegroundColor Gray
Write-Host " Args: -projectfiles -project=`"$UProjectPath`" -game -engine" -ForegroundColor Gray
Write-Host "`n=== DRY RUN COMPLETE ===" -ForegroundColor Magenta
Write-Host "Run without -DryRun to perform these actions." -ForegroundColor Magenta
} else {
Write-Host "Regenerating Visual Studio project files..." -ForegroundColor Yellow
& $buildBat -projectfiles -project="$UProjectPath" -game -engine
if ($LASTEXITCODE -eq 0) {
Write-Host "`nDone! You can now reopen your solution in Visual Studio." -ForegroundColor Green
} else {
Write-Error "Failed to regenerate project files (exit code: $LASTEXITCODE)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment