Skip to content

Unexpected behavior on folders with no projects #222

Open

Description

@mio-moto

I was debugging today a problem with our CI environment on my development machine and noticed a strange bug where the Editor was upgrading randomly, not noticing that my terminal went back to my home folder.

PS C:\Users\mio> Start-UnityEditor -Wait -LogFile build.txt -AdditionalArguments " -buildPlatform Desktop -buildOutput $PWD\Build -buildTarget Win64 "  -ExecuteMethod BuildTools.Pipeline.StartCommandLineBuild -Batchmode -WhatIf
What if: Performing the operation "System.Diagnostics.Process.Start()" on target "C:\Program Files\Unity\Hub\Editor\2020.2.1f1\Editor\Unity.exe -executeMethod BuildTools.Pipeline.StartCommandLineBuild -logFile build.txt -batchmode  -buildPlatform Desktop -buildOutput C:\Users\mio\Build -buildTarget Win64 ".

That is no bug per-se, the command line utility selects the latest editor (due to the missing ProjectVersion.txt). However, the editor still executes fine - because Unity does store the last opened project somewhere (I'm guessing either by registry key or somewhere in LocalAppData), and opens that.

Start-UnityEditor falls back to the latest version, starts the Editor, which then opens the last opened project, no matter which ProjectVersion.txt.

Reproduction

Execute Start-UnityEditor in a folder that does not contain a Unity project

Possible Solutions

Start-UnityEditor should either be able to find the folder that Unity is going to open or exit prematurely with an error code that this folder is not a Unity project folder.

Activity

  1. jwittner commented on Jul 6, 2021

    @jwittner
    Member

    Interesting, when I run Start-UnityEditor from a non-unity project folder I essentially get the Unity Hub to open. It's an interesting bit of confusion, but this working as intended currently. If there's a unity project and you haven't passed -IgnoreProjectContext then it launches the latest version of Unity, which Unity has changed to fall back to the Hub if installed and there's no unity project specified I believe. This gives one a quick way to get into Unity from the command line if you don't have a project available.

    What might make sense though is to look at what other arguments have come in to Start-UnityEditor and if they seem like they'd only make sense if a project is discovered/specified, then throw the error?

  2. changed the title [-]Incorrect editor version on folders with no projects[/-] [+]Unexpected behavior on folders with no projects[/+] on Jul 6, 2021
  3. jwittner commented on Jul 6, 2021

    @jwittner
    Member

    Retitled as there really is no 'incorrect version' on projects without a folder.

  4. mio-moto commented on Jul 6, 2021

    @mio-moto
    Author

    If I had to guesstimate, then Unity is not opening the hub either because of -batchmode, since it already assumes that there is no UI involved. Probably good guess that -nographics does something similar (but I have yet to test that either).

    I think your additions generally make sense, it's not actively hurting (our) CI process, it's most a side-effect I have discovered while working on our CIs

  5. mister-liss commented on Feb 17, 2022

    @mister-liss

    I have seen another variant of this issue recently. In our CI, when we open Unity with the intent to license it, Unity is consistently emitting a new empty project into the WorkingDirectory. I could not replicate this on my local machine. Locally, I saw what the above users mentioned, either Unity opened a cached project or if there was no cached project, the hub would open. I circumvented the issue by explicitly using the "-CreateProject" flag to create a decoy project in the build machine's Temp folder when licensing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions