Last active
November 23, 2020 03:11
-
-
Save instance-id/185c223ccad39dceb69ecd94763ec376 to your computer and use it in GitHub Desktop.
Unity: "Failed to load layout window" fix. See new version : https://gist.github.com/instance-id/3161cc2b5343db5bc3cef494d83a7449
This file contains 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
#-------------------------------------------------------------------------------------------------------------- | |
# This has been updated and changed to include several new features. See the link below for updated version: -- | |
# https://gist.github.com/instance-id/3161cc2b5343db5bc3cef494d83a7449 ---------------------------------------- | |
#-------------------------------------------------------------------------------------------------------------- | |
# Replace folder paths in $projectLocations array (line 20) with your actual Unity project folder path(s) | |
# Usage: .\unityfixlayout.ps1 -Project MyProjectName | |
Param ( | |
[Parameter()] | |
[string]$Project | |
) | |
# Checking to make sure project name and Unity version are included | |
if ($Project) { | |
Write-Host "Fixing layout ${Project}: ${versionNumber}..." | |
} | |
else { | |
Write-Host "Unity project name and version required..." | |
exit | |
} | |
# Input the root folder location(s) that contain your Unity projects ----------------------- | |
# Ex: "C:\Unity\MyProjects" : Can be multiple locations separated by comma | |
$projectLocations = "E:\GitHub\instance-id", "E:\_unity\_projects" | |
# ------------------------------------------------------------------------------------------ | |
# Needed variables for file names and locations | |
$originalLayout = "Default.wlt" | |
$destinationLayout = "CurrentLayout-default.dwlt" | |
$backupLayout = "CurrentLayout-default.dwlt.bak" | |
$destinationLayoutPath = "\Library\${destinationLayout}" | |
$versionNumber = "" | |
foreach ($projectFolder in $projectLocations) { | |
$projectFolder = "$projectFolder\${Project}" | |
if (Test-Path "$projectFolder") { | |
# Getting Unity versionNumber from ProjectSettings | |
$projectVersionLocation = "\ProjectSettings\ProjectVersion.txt" | |
$destinationPath = "${projectFolder}${destinationLayoutPath}" | |
$projectVersionFile = "${projectFolder}${projectVersionLocation}" | |
Write-Host "Unity project $Project found: $projectFolder" | |
Write-Host "Unity project version file found: $projectVersionFile" | |
$file_data = Get-Content $projectVersionFile | Where-Object { $_ -like ‘*m_EditorVersion: *’; } | |
$separator = ": " | |
$versionString = $file_data.split($separator); | |
$versionNumber = ${versionString}[1] | |
# Default Unity hub installation folder. If yours are installed in a non-default folder please update accordingly | |
$originalLayoutFile = "C:\Program Files\Unity\Hub\Editor\$versionNumber\Editor\Data\Resources\Layouts\$originalLayout" | |
# Checking if provided Unity version exists in specified installation folder location | |
if (Test-Path $originalLayoutFile) { | |
Write-Host "Original layout file for Unity version $versionNumber found..." | |
if ([System.IO.File]::Exists($destinationPath)) { | |
Write-Host "Probematic layout file found: $destinationPath" | |
# Backup original layout file | |
Write-Host "Creating backup of original layout file at: ${destinationPath}.bak" | |
Copy-item -Force -Verbose -Path ${destinationPath} -Destination "${destinationPath}.bak" | |
# Copy Default layout for editor version from install folder and rename to required filename | |
Write-Host "Copying default layout for version $versionNumber to $Project Library..." | |
Copy-item -Force -Verbose -Path $originalLayoutFile -Destination "${destinationPath}" | |
} | |
else { | |
Write-Host "Could not locate probematic layout file at location: $destinationPath" | |
Write-Host "Please check that Library folder exists at path: ${projectFolder}\Library" | |
} | |
} | |
else { | |
"Unity $versionNumber not found" | |
return; | |
} | |
} | |
} | |
Write-Host "Layout fix completed" | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is currently only set up for Windows, but since Powershell is now cross-platform if there is any interest/need I can make it work on Linux/Mac.