We would like to integrate UE4 more into our pipeline. We’re particularly interested in automating UE4 related processes via commandline and python scripts. I’ve had a look at the existing documentation:
What’s the difference between UE4Editor.exe and UE4Editor-Cmd.exe? They both seem to behave the same, and both bring up the GUI. Any preference on which one to use when using UE4 ‘headless’ via the command line?
How to get logging output from UE4 when using it via the commandline? By default it seems to by totally silent and doesn’t output to stdout or stderr. In order to interact with it properly vie the commandline, we’d need to be able to capture output logging.
Ideally we’d be calling it from within other (non-UE4) Python processes like this:
result = subprocess.call('UE4Editor-Cmd.exe -run=pythonscript -script="c:\my_script.py"', stdout=subprocess.PIPE, stderr=subprocess.PIPE )
Any advice on best practice there?
Any help much appreciated!
This is pretty old but since there were no answers and I ran into the same problem, I’ll share what I learned.
I know that UE4Editor.exe is the full editor and UE4Editor-Cmd.exe “commandlet mode” and intended to run UCommandlets I wasn’t able to get it to successfully run a commandlet though. I’m not sure if it was my game code or not. I decided to run UE4Editor.exe with -nullrhi to run it headless.
I am also having issues running UEditor -Cmd.exe in because of Oculus failing to initialize in Commandlet mode.
Do you have exact syntax for running UE4Editor.exe in headless mode, and executing a Python script?
I don’t know what you mean by executing a Python script, but the syntax I used was: UE4Editor.exe MyProjectName -nullrhi -stdout -ExecCmds=“My Exec Command;”
I was attempting to use this syntax to run a Python script in Commandlet mode:
UE4Editor-Cmd.exe “C:\projects\MyProject.uproject” -run=pythonscript -script=“c:\my_script.py”
Fails because Oculus is unable to initialize in Commandlet mode:
LogOnline: Warning: Oculus: Failed to initialize the Oculus Platform SDK! Failure code: -5
LogOnline: Warning: Oculus: Oculus API failed to initialize!
Was looking for another was to run the UE4Editor from command line, and execute a Python script?
To answer your first question:
UE4Editor.exe is the editor itself. UE4Editor-Cmd.exe is the command-line for the editor. I’m actually really surprised to hear that UE4Editor-Cmd.exe is opening up the GUI for you. I’ve had it open “live coding” before, but that’s about it.
I’m not sure about how to do this in Python, but here’s a way of doing it in C#, maybe you can figure it out how to convert that to Python.
Process myProcess = new Process();
Process myProcess = new Process();
myProcess .StartInfo.FileName = UE4EditorCmd; //Relative path to UE4Editor.exe
myProcess .StartInfo.Arguments = "myProject.uproject -run=pythonscript"
myProcess .ErrorDataReceived += MyErrorFunc;
myProcess .OutputDataReceived += MyOutputFunc;
myProcess .Start();
myProcess.BeginErrorReadLine();
myProcess.BeginOutputReadLine();
try
{
if (myProcess.WaitForExit(maxTime))
{
//test for different results. A result of 1, 2 or 3 doesn't mean it failed.
//A result with a negative number means it crashed.
}
internal static void MyErrorFunc(object _sender, DataReceivedEventArgs _event)
{
Console.WriteLine(_event.Data);
}
//Same idea for MyOutputFunc
I was searching for the same info and found this after some digging. Posting for clarity. There is an addon called “PythonScriptPlugin” which has a remote_execution function you can use. After installing the plugin you can check out this file for info on the commands:
Engine\Plugins\Experimental\PythonScriptPlugin\Content\Python\remote_execution.py