Python for Unity - Threading

Apologies if this has been covered before but I couldn’t find an answer anywhere.

Does Unity support threading in Python?
I’ve got a PySide2 interface which relies on a bunch of web queries and I’m trying to move those off the main thread so that the UI doesn’t freeze.

Using QThread I find that the thread never executes and when using QRunnable the editor crashes. Just wondering if I’ve missed something obvious somewhere or whether it’s just not supported yet.

Cheers,

Mark

Just to be clear, you’re on Python 4.0.0-exp.1 right?

All calls to Unity or to any C# code must be done on the main thread – even if you just import a module implemented in C#, it needs to be imported on the main thread. Otherwise the editor can crash or hang indefinitely.

Other than that, it’s supposed to work to have threads that are entirely in the Python universe doing their thing; indeed the PySide sample has multiple threads.

1 Like