Skip to content

Instantly share code, notes, and snippets.

@maoyeedy
Created May 7, 2025 18:50
Show Gist options
  • Save maoyeedy/d212f38730348d2dbe6e1d2abdde21ab to your computer and use it in GitHub Desktop.
Save maoyeedy/d212f38730348d2dbe6e1d2abdde21ab to your computer and use it in GitHub Desktop.
Find Unity editor installations from Unity Hub
function Get-UnityInstallationRoot {
$userPathFile = "$env:APPDATA\UnityHub\secondaryInstallPath.json"
# Check if Unity Hub is installed, if installed, then must come with this file
if (-not (Test-Path $userPathFile)) {
Write-Warning "Unity Hub not installed."
return $null
}
# By default, it only has two quotes: ""
# So $userPath will be empty string by default
$userPath = (Get-Content $userPathFile -Raw).Trim('"')
# If userPath directory is set but deleted.
# Unity Hub will recreate directory upon next Editor installation.
if ((Test-Path $userPath)) {
return $userPath
}
# Default path
$defaultPath = "$env:ProgramFiles\Unity\Hub\Editor"
if (Test-Path $defaultPath) {
return $defaultPath
}
Write-Warning "Could not determine Unity Editor installation path."
return $null
}
Get-UnityInstallationRoot | Get-ChildItem | Select-Object FullName
@maoyeedy
Copy link
Author

maoyeedy commented May 7, 2025

The %APPDATA%/UnityHub/secondaryInstallPath.json should be "" by default unless user override the setting👇

image

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