Created
May 7, 2025 18:50
-
-
Save maoyeedy/d212f38730348d2dbe6e1d2abdde21ab to your computer and use it in GitHub Desktop.
Find Unity editor installations from Unity Hub
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
%APPDATA%/UnityHub/secondaryInstallPath.json
should be""
by default unless user override the setting👇