UnityEngine.Texture2D(...) thread safe ?

I am trying to dynamically load external image assets, and avoid any visual lag in unity when doing so.

So far i can decode the image bytes in another thread, but can i also create the 2d texture outside Unity main thread ?

I am targetting the windows platform with directX, and i know directx calls can be thread safe.

1 Answer

1

You can load them up into a Color32[] and then SetPixels32 later. Color32 is thread safe.

Just to make that clear: Yes you can prepare the raw image color data in a seperate thread. No you can not use the Texture2D constructor from any other thread than the main thread. However there are ways to [create native textures in a low level native code plugin][1]. Though you really have to be careful when dealing with multiple threads and native pointers. [1]: https://forum.unity.com/threads/unity-native-texture-create-release-causes-gpu-suspension.437858/