Reputation: 300
Sometimes I build my project in Unity Editor and it takes way less than a minute.
But I also like to do a command line build and I noticed that takes ten minutes. Is there a way I can fix that so it builds faster? Here is what my command line looks like -- I use powershell so that the batch file does not continue before the build actually finishes. Maybe it has to do with the "-Wait" but if I don't put that in the command line continues before the build finishes.
powershell -Command "Start-Process -FilePath C:\Users\me\source\Unity\Editors\2019.3.5f1\Editor\Unity.exe -ArgumentList '-batchmode -projectpath C:\Users\me\source\repos\MyProject -buildWindows64Player C:\mybuild\MyProject.exe -quit' -Wait" time /T
Upvotes: 4
Views: 2023
Reputation: 13386
I had some trouble getting @Luther's answer to work in Powershell Core, here's a similar solution that uses Get-CimInstance
instead of Get-WmiObject
:
$unity_args = "-quit -batchmode -disable-assembly-updater -projectpath `"$project_path`" -buildWindowsPlayer `"$output_path`" -logFile `"$log_path`""
$unity = Start-Process `
-FilePath "$unity_path" `
-ArgumentList $unity_args `
-PassThru
Start-Sleep -Seconds 3.0
# wait for all other sub-processes to complete
while ((Get-CimInstance -Class Win32_Process | Where-Object {$_.ParentProcessID -eq $unity.Id -and $_.Name -ne 'VBCSCompiler.exe'}).count -gt 0) {
Start-Sleep -Seconds 1.0
}
if (!$unity.HasExited) {
Wait-Process -Id $unity.Id
}
exit $unity.ExitCode
Upvotes: 1
Reputation: 300
I finally figured this out by closely watching processes when I was building. It turns out that if you have scripts, the build process causes VBCSCompiler.exe to run as well. If this was launched by Unity then it will be part of the process tree that was launched. It stays open for ten minutes in case there is more work for it to do. See here for more info.
So to work around this, I changed my code:
powershell -Command "$unity = Start-Process -FilePath C:\Users\me\source\Unity\Editors\2019.3.5f1\Editor\Unity.exe -ArgumentList '-batchmode -projectpath C:\Users\me\source\repos\MyProject -buildWindows64Player C:\mybuild\MyProject.exe -quit' -PassThru; Start-Sleep -Seconds 3.0; Write-Host -NoNewLine 'Building...'; while ((Get-WmiObject -Class Win32_Process | Where-Object {$_.ParentProcessID -eq $unity.Id -and $_.Name -ne 'VBCSCompiler.exe'}).count -gt 0) { Start-Sleep -Seconds 1.0; Write-Host -NoNewLine '.' }; if (!$unity.HasExited) { Wait-Process -Id $unity.Id }; exit $unity.ExitCode"
Upvotes: 4