Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Multithreading in Unity

Discussion in 'Scripting' started by tokareuv, Mar 22, 2017.

  1. tokareuv

    tokareuv

    Joined:
    Sep 28, 2016
    Posts:
    6
    Hello everybody!
    I'm going to use Unwrapping.GenerateSecondaryUVSet(Mesh) for, obviously, generating array of UV2 if it doesn't exist. Mostly, it takes too much of time to create it. This method is, as I see, static.
    Therefore, my question. Is there any possibility to use threads for generating UV2 in several threads? I have 4 cores in processor and Unity 5.4.4f, but main question still, is it even possible? More than that, I've heard that Unity mostly is not thread-safe and it even doesn't safe to work with mesh objects using multithreading.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    well for 1... you could always just run some test code and see what happens, if unity doesn't let you it'll throw an exception saying as such.

    and 2... I'm willing to bet it won't be able to be called from a thread since it's going to access a Mesh object, and unity doesn't like its objects accessed from a separate thread.

    The Unity engine is not thread safe, it complains if you access most of its API from a separate thread. You're welcome to thread your own code, but you must always return to the main thread if you want to interact with the Unity engine.
     
    tokareuv likes this.
  3. parandham03

    parandham03

    Joined:
    May 2, 2012
    Posts:
    174
    tokareuv likes this.