Project path from command line doesn't always switch

I have set up Jenkins to build our Unity projects. It takes the project from git and builds Windows and Web simultaneously. I use seperate project folders for each build type so that Unity doesn’t trip over itself when compiling. 99.9% of the time this works just fine, and I see log files that look like the following:

 BATCHMODE ARGUMENTS:
C:\Program Files (x86)\Unity-4.5\Editor\Unity.exe
-projectPath
C:\Jenkins\jobs\unity-web\workspace
-quit
-batchmode
-nographics
-logFile
C:\Jenkins\jobs\unity-web\workspace\bin\build.log
-buildWebPlayer
C:\Jenkins\jobs\unity-web\workspace\bin\my-game
Successfully changed project path to: C:\Jenkins\jobs\unity-web\workspace
C:/Jenkins/jobs/unity-web/workspace

0.1% of the time it doesn’t work:

 BATCHMODE ARGUMENTS:
C:\Program Files (x86)\Unity-4.5\Editor\Unity.exe
-projectPath
C:\Jenkins\jobs\unity-web\workspace
-quit
-batchmode
-nographics
-logFile
C:\Jenkins\jobs\unity-web\workspace\bin\build.log
-buildWebPlayer
C:\Jenkins\jobs\unity-web\workspace\bin\my-game
Successfully changed project path to: C:\Jenkins\jobs\unity-web\workspace
C:/Jenkins/jobs/unity-windows/workspace

The important parts are on lines 11 - 13. Even though I have specified a project path of “unity-web\workspace” and Unity reports it has successfully changed the project path to “unity-web\workspace” it then reports it is using “unity-windows\workspace”. I know this is a problem because my Windows build process shows the following:

 BATCHMODE ARGUMENTS:
C:\Program Files (x86)\Unity-4.5\Editor\Unity.exe
-projectPath
C:\Jenkins\jobs\unity-windows\workspace
-quit
-batchmode
-nographics
-logFile
C:\Jenkins\jobs\unity-windows\workspace\bin\build.log
-buildWindowsPlayer
C:\Jenkins\jobs\unity-windows\workspace\bin\my-game.exe
Successfully changed project path to: C:\Jenkins\jobs\unity-windows\workspace
C:/Jenkins/jobs/unity-windows/workspace
It looks like another Unity instance is running with this project open.

Multiple Unity instances cannot open the same project.

Project: C:/Jenkins/jobs/unity-windows/workspace
 
(Filename: C:/BuildAgent/work/d63dfc6385190b60/Editor/Src/Application.cpp Line: 251)


Aborting batchmode due to failure:
Fatal error! It looks like another Unity instance is running with this project open.

Multiple Unity instances cannot open the same project.

Project: C:/Jenkins/jobs/unity-windows/workspace

Why does Unity occasionally use the wrong project path and how can I force it to always use the correct one?

1 Like

I’m guessing that concurrently launching multiple batch mode instances of Unity isn’t a common use case, so it could very well be a bug that no one has managed to notice until now. Might be worth reporting it.

Issue created. Interestingly, I have encountered the problem even when I use two different instances of Unity installations (on the same machine)

Job 1 (works)

BATCHMODE ARGUMENTS:
C:\Program Files (x86)\Unity-4.5-Web\Editor\Unity.exe
-projectPath
C:\Jenkins\jobs\unity-web\workspace
-quit
-batchmode
-nographics
-logFile
C:\Jenkins\jobs\unity-web\workspace\bin\build.log
-buildWebPlayer
C:\Jenkins\jobs\unity-web\workspace\bin\my-game
Successfully changed project path to: C:\Jenkins\jobs\unity-web\workspace
C:\Jenkins\jobs\unity-web\workspace

Job 2 (fails)

BATCHMODE ARGUMENTS:
C:\Program Files (x86)\Unity-4.5\Editor\Unity.exe
-projectPath
C:\Jenkins\jobs\unity-windows\workspace
-quit
-batchmode
-nographics
-logFile
C:\Jenkins\jobs\unity-windows\workspace\bin\build.log
-buildWindowsPlayer
C:\Jenkins\jobs\unity-windows\workspace\bin\my-game.exe
Successfully changed project path to: C:\Jenkins\jobs\unity-windows\workspace
C:\Jenkins\jobs\unity-web\workspace
It looks like another Unity instance is running with this project open.

Multiple Unity instances cannot open the same project.

This issue was fixed in Unity 4.6.2p1.

I’m actually having this same issue, but with unity 2017.3.1p1 and can’t find why this is happening

COMMAND LINE ARGUMENTS:
/Applications/Unity 2017.3.1p1/Unity.app/Contents/MacOS/Unity
-quit
-batchmode
-nographics
-logFile
/Users/Shared/Jenkins/Home/workspace/Game/Builds/Staging/Artifacts/270/buildLog.log
-projectPath
/Users/Shared/Jenkins/Home/workspace/Game/Builds/Staging/LocalRepo/Unity
-buildTarget
iOS
-executeMethod
BuildScript.BatchBuild
+buildPath
/Users/Shared/Jenkins/Home/workspace/Game/Builds/Staging/
+buildPlatform
iOS
+buildEnv
Staging
/Users/Shared/Jenkins/Home/workspace/Game/Builds/Production/LocalRepo/Unity

This is a OSX env

1 Like

Did you resolve this?

I appear to be having similar issue using unity 2020.3.24f1 on Windows platform.
I started work in one workspace, then switched to another and afaik things were working as expected.
But then when I switched back to the first things were getting mixed up.
Now switching to the second (which had been working) is also broken (I can see for example, that the shader compiler is referencing files in the first workspace).