I am generating a lot of procedural meshes (many thousands) which I am then saving to the AssetDatabase. The process of creating the mesh asset in the AssetDatabase seems to be fairly slow.
To deal with the performance penalty, I am limiting the addition of new assets to once a frame (using a coroutine), however, this still slows the framerate to below 15 p/s. As the meshes are generated, they are added to a queue, which the coroutine then dequeues and saves to the AssetDatabase.
Is there a way to speed this process up? Or is there another manner to use the AssetDatabase that is more performant?
Here is the code:
public class Cache_Manager : MonoBehaviour
{
public static Queue <q_struct> cache_build_q = new Queue<q_struct> ();
public IEnumerator cache_coroutine ()
{
Debug.Log ("...starting cache builder coroutine");
while (true) {
if (cache_build_q.Count > 0) {
q_struct item = cache_build_q.Dequeue ();
AssetDatabase.CreateAsset (item.mesh, "Assets/UnityLondon3D/cache/" + item.id.ToString () + ".asset");
}
yield return 0;
}
}
IEnumerator Start ()
{
yield return StartCoroutine (cache_coroutine ());
}
public struct q_struct
{
public string id;
public Mesh mesh;
public q_struct (string _id, Mesh _mesh)
{
id = _id;
mesh = _mesh;
}
}