Unity from the Command Line in Linux

I go through a LOT of unity projects. It would be *so* cool to automate the first open, so that I don’t have to import all projects into UnityHub and wait for the build process. With some automation I could let my computer build 90 Unity projects and once it’s done, I could start taking a look.

For that, we can use the command line!

$ /home/myname/Unity/Hub/Editor/6000.2.7f2/Editor/Unity \
   -projectpath /some/path/somewhere

Except, apparently, we can’t?

This message pops up and cannot be interacted with.

How Unity is invoked by UnityHub

If we instead open a Unity project from UnityHub the intended (boring, slow, high-overhead) way, the command line looks like this:

$ /home/myname/Unity/Hub/Editor/6000.2.7f2/Editor/Unity \
  -projectpath /some/path/somewhere \
  -useHub \
  -hubIPC \
  -cloudEnvironment production \
  -licensingIpc LicenseClient-myname \
  -hubSessionId some-uuid \
  -accessToken some-token

The hubSession UUID seems to stay the same as long as UnityHub is running. The accessToken is different for some Unity projects, but also sometimes reused. This will need more investigation. It might be a short lived token that gets cycled every hour or something along those lines.

Information like this can be found in /proc/process-id/cmdline.

If we replicate this exact pattern, we can try starting this on our own including those extra bits and pieces, but it will still fail.

Taking a look at the environment

The environments of both processes (as seen in /proc/process-id/environ look vastly different. Most of that comes from the fact that UnityHub is a Flatpak program, and that likely means all Unity processes that are installed by it will themselves be started within that sandbox.

There is a one env-var that looks unity-specific though:

UNITY_DATADIR=/home/myname/.var/app/com.unity.UnityHub/data

But even including that only gets me the Licensing box above.

Running within Flatpak

So let’s try opening this in flatpak. Let’s start with a boring shell in that same container:

flatpak run --command=sh com.unity.UnityHub

Its environment looks much more similar to the one we observed from a working Unity process. Let’s start a Unity process from within this shell in the simple way that we tried all the way at the beginning:

/home/myname/Unity/Hub/Editor/6000.2.7f2/Editor/Unity \
  -projectpath /some/path/somewhere

And it immediately works. No extra stuff about licenses needed!


Leave a Reply


Author

Claudius Coenen is a tech-enthusiast. He's writing on all kinds of topics, including programming, technology, gadgets and media.

This site features his occasional articles, findings, documentations.

Categories

Connect

RSS Recent Bookmarks

Legal