Detect if standalone build is running batchmode?

How can we detect if a standalone build is running batchmode?

In another thread I picked up we cannot read the original command line parameters (since we call the .exe with -batchmode)

A very hacky option I came up with is checking the Screen.width and height, it reports “1254x713” here, and that’s not one of the common resolutions. However, I don’t know how it comes up with this value, and it will probably be different per machine anyway. It might even change if I change my screen somehow…

The other screen/resolution functions all report the same values as a normal running application.

Maybe there is a need for something like Application.isBatchMode, but it doesn’t seem to exist at the moment. The only thing I can think of is to add a routine somewhere that sets a flag indicating batch mode. The executeMethod command line option could then be used to run this routine. Not very elegant, but it might avoid the issue of the screen size thing being machine-specific.

Isn’t "executeMethod " editor only?

At the moment I found another workaround;
I’m using a .bat file to create a “dedicated.txt” file, and then make it run the .exe with -batchmode.

The preloader in my application checks if the dedicated.txt file exists, and if so; sets flags inside the program and it deletes the dedicated.txt file.

Another method mentioned here is to check if graphicsDeviceType is Null.

using UnityEngine.Rendering;

// detect headless mode (which has graphicsDeviceType Null)
bool IsHeadless() {
return SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null;
}