Open Unity project from CLI / Terminal

I’d like to submit a feature request for
Feature:
Ability to open a Unity project, in the proper editor version, without the CLI command needing to contain anything other than the path to the Unity Hub (constant) + path-to-project.

Usage:
uhub --open --projectPath "Repos/UnityProject"

1 Like

Additional to open I wish I could just add path of project to unity hub

Actually it should have all command relate to project. Add / List / Open / Remove

With the same pattern as editors command it should be unityhub -- --headless projects -list unityhub -- --headless projects -add "path" unityhub -- --headless projects -open "path"

And open command should have version enforcer such as --unityversion=2022.3.5f and preemtive prompt, such as --switchversion=true and --error=ignore or --error=safemode

1 Like

Until someone at unity gets around to it, here’s a script to open the project from the correct hub editor version

# Launch a unity project with the right editor

# The current working directory has to be the root of the project
# cd /path/to/UnityProject
HUB_PATH="C:\Program Files\Unity Hub\Unity Hub.exe"

# Extract into variable via sed
PROJECT_VERSION=$(sed -nE 's/m_EditorVersion: (.+)/\1/p' ProjectSettings/ProjectVersion.txt)

# Display
echo "$PROJECT_VERSION"

# Get hub version

# editors - i :
#2021.X.Xf1 , installed at C:\Program Files\Unity\Hub\Editor\2021.X.Xf1\Editor\Unity.exe
#2022.X.Xf1 , installed at C:\Program Files\Unity\Hub\Editor\2022.X.Xf1\Editor\Unity.exe
#2023.X.Xf1 , installed at C:\Program Files\Unity\Hub\Editor\2023.X.Xf1\Editor\Unity.exe

# grep "$PROJECT_VERSION"
# 2022.X.Xf1 , installed at C:\Program Files\Unity\Hub\Editor\2022.X.Xf1\Editor\Unity.exe

# cut -d\  -f5-
# C:\Program Files\Unity\Hub\Editor\2022.X.Xf1\Editor\Unity.exe

PROJECT_VERSIONS=$("$HUB_PATH" -- --headless editors -i)

PROJECT_PATH=$(echo "$PROJECT_VERSIONS" | grep "$PROJECT_VERSION" | cut -d\  -f5-)

# Display

echo "$PROJECT_PATH"

# Launch Unity

nohup "$PROJECT_PATH" -projectPath . >/dev/null 2>&1 &
1 Like

Hey all,

not many people use the hub CLI. Please show your support for it by requesting these features via the official channel https://portal.productboard.com/bjw67qlvvmhbaakvfgzccpk8/c/1073-submit-a-new-idea

That will help us to be able to work on this stuff :slight_smile:

productboard is very unwieldy. It even cannot login with unity id and instead need to put email manually. And we can’t comment anything on it is paint point

Fair enough, I agree it is dated. I passed on your comments to our product team.

not many people use the hub CLI BECAUSE HUB CLI never ever have command that we actually need to use

Many command that unity hub can do by GUI was not exist in cli and that is what we actually need to use hub cli for

1 Like

With my new unity-cli npm package it is as simple as: unity-cli open-project if you’re in the working directory of your unity project, otherwise unity-cli open-project -p /path/to/your/unity/project.

npm install -g @rage-against-the-pixel/unity-cli
unity-cli open-project -p /path/to/your/unity/project
1 Like