Batchmode, how do you write to the console, so the user knows when it is done?

I’m trying to write a script to automatically import, organize, and rename assets, then export an Asset Bundle, in the Unity Editor from the command line in Windows. But when I run it, the commandline immediately returns while Unity is loading, running my script, etc. There’s no way to know the status, when it is finished, if there were any errors, there’s no feedback at all, no way to know if it is even doing anything. How do I stop the commandline from immediately returning, and write messages to the console? Apparently you used to be able to do -logFile with no arguments to redirect all logging to the console, that doesn’t work anymore (which makes sense since the console returns from Unity immediately).

Here’s my current commandline:
\path_to_unity\unity.exe -batchmode -executeMethod ImportAndCreateAssetBundle.Import -quit -logFile

Is it possible to do it without batchmode, so that Unity still pops up something the user can see and I can control, but without asking which project to load and all that, and still quit when it is done? This isn’t as ideal but it’s a lot better than no feedback at all.

From what I can tell from my research, it is impossible to do what I want with the Unity commandline or API. However, I have found an alternative solution! 3 years ago the developer of Rust wrote a class for hooking directly into Windows’ console to send messages (and accept input, but all I needed was the message system).

https://garry.tv/2014/04/23/unity-batchmode-console/

It’s not perfect, though - when Unity is first run, it imports assets, which can take a considerable amount of time, and until it is done the user has no feedback.

2 Likes

In any batchmode run you can specify a log file location with an argument -logFile, this file will be written into live during the execution of the given method. You can easily monitor the file using different commands. One of them is from powershell: get-content “c:\location-to-your-log.log” -wait
This one will “tail” the file.

2 Likes