I recently taught a course that focused on Unity. Now I have dozens of repositories that I need to take a look at. I don’t particularly like the Unity Hub, but as far as I know, I still need to use it anyway.
So, how do I get all these projects in there?
Surely, UnityHub must store its project list somewhere.
$ ps -ef | grep -i unity
This gives me a couple of unity processes that are running on my system. I’m simply choosing the first from that list, in this case, it’s process ID 143607
. Your number will vary.
Next, let’s see what files this process has open.
$ lsof -p 143607 -a /home
Make sure to replace the process ID with the one you found earlier! This will give us a list of all open files in our home directory. This tells me where the this particular setup stores its configuration. For me, this is /home/<username>/.var/app/com.unity.UnityHub/config/unityhub
.
I hope that this is stored in a relatively simple way, and since this whole structure is just 22MB on my disk, I just decide to grep through ALL OF IT with a name that I know must be in there somewhere.
$ grep -lr Example-Project
logs/info-log.json
projects-v1.json
Two files contain that name! Both of them are JSON, so after looking at them, I now know that projects-v1.json
must be, where that UnityHub-List comes from. It contains Entries like these
$ jq . projects-v1.json
{
"schema_version": "v1",
"data": {
"/home/<username>/Example Project": {
"title": "Example Project",
"lastModified": 1739361302837,
"isCustomEditor": false,
"path": "/home/<username>/Example Project",
"containingFolderPath": "/home/<username>",
"version": "2022.3.53f1",
"architecture": "x86_64",
"changeset": "abcdef",
"isFavorite": false,
"localProjectId": "f1677218d0c2cf8018498b4019580b73",
"cloudEnabled": true
}
}
}
This is very straightforward. The entries in data
are plentiful. The only thing I worry about is the localProjectId
. Let’s see if I can just provite whatever I want in there, or if this can be found in the actual project somehow:
# (in the related project directory!)
$ grep -lr f1677218d0c2cf8018498b4019580b73
ProjectSettings/ProjectSettings.asset
Ok, so it is also stored in the ProjectSettings. It is part of
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 26
productGUID: f1677218d0c2cf8018498b4019580b73
AndroidProfiler: 0
# ... and so on ...
Let’s see if that matters? I modify the ProjectSettings.asset
file to be something else. I also change the projects-v1.json
to totally remove that localProjectId
. After reopening UnityHub, the project is still in the list and it opens up just fine. Great, let’s just ignore this part! Also, the
So, all I need to do now is create that JSON structure from a bunch of directories I have on my drive. Sadly, writing a desired unity version in there does not get applied, you still will need to select it from a dropdown, because apparently UnityHub reads the information from the project instead.
Right now, you also need to integrate the output of my script into the existing JSON manually, but I will probably not change that. It’s a relatively rare occasion where I need to do that and that file’s structure is very simple.
So, this script now lives in my university-automation repository under Unity-United. If this is something you might need, feel free to give it a try!