Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Python for Unity - Threading

Discussion in 'Formats & External Tools Previews' started by mdooneymill, Jun 21, 2021.

  1. mdooneymill


    Feb 7, 2019
    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.


  2. bhudson


    Nov 21, 2014
    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.
    mdooneymill likes this.