Unity: Difference between revisions

31 bytes added ,  8 January 2021
Line 25: Line 25:
[https://assetstore.unity.com/packages/tools/thread-ninja-multithread-coroutine-15717 Ciela Spike's Thread Ninja] may be used to run coroutines in the background when you only need a single, but complex, task.<br>
[https://assetstore.unity.com/packages/tools/thread-ninja-multithread-coroutine-15717 Ciela Spike's Thread Ninja] may be used to run coroutines in the background when you only need a single, but complex, task.<br>
Much of Unity's API for GPU assets such as <code>new Mesh()</code> and <code>new Texture2D()</code> cannot be called from background threads.
Much of Unity's API for GPU assets such as <code>new Mesh()</code> and <code>new Texture2D()</code> cannot be called from background threads.
I suggest caching textures as <code>byte[]</code> or <code>Color32[]</code> which can then be loaded with [https://docs.unity3d.com/ScriptReference/Texture2D.LoadRawTextureData.html <code>Texture2D.LoadRawImageData()</code>]. Similarly, you can cache a Mesh by caching a struct of vertices, triangles, normals, and tangents.
I suggest caching textures in system memory as <code>byte[]</code> or <code>Color32[]</code> which can then be loaded with [https://docs.unity3d.com/ScriptReference/Texture2D.LoadRawTextureData.html <code>Texture2D.LoadRawImageData()</code>]. Similarly, you can hold a Mesh in system memory by using a struct of vertices, triangles, normals, and tangents.


===Instancing===
===Instancing===