Control Unreal using a port through Python

Hey everyone,

I’m working on a solution that enables a back and forth communication channel between Maya and Unreal using Python. The goal is to be able to run commands from one software that do things in the other. This works from Unreal to Maya surprisingly well without the need of using the built-in ‘cmds.commandPort’ feature.

The connection is managed by the socket module in Python and to trigger them to execute the messages I am using eval an/or exec functions with the globals() flag.

This works beautifully on Maya side, however when I try running Unreal commands from Maya I get this error:

LogEditorScripting: Error: You are not on the main thread.

I’m hoping someone with a better Unreal understanding would be able to tell me why this happens and how to overcome it, because currently it seems to be a biggie.

Thank you!

You cannot call other Blueprint and scripts and UI outside of the main thread.
You can marshal calls to the main thread using a task with the TaskGraphMainThread run mode. EAsyncExecution | Unreal Engine Documentation
Check out Async.h for more details.
If you’re not writing any C++, and just have to use Python, I don’t have a good answer for you, because while I’ve integrated with Python in the past, I haven’t done so in Unreal.