Simple code of creating 1000 quad meshes:
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;
public class TestSystem : ComponentSystem
{
Material mat = new Material(Shader.Find("Standard"));
protected override void OnCreate()
{
for (int i = 0; i < 1000; i++)
{
Mesh mesh = new Mesh();
mesh.vertices = new Vector3[] { new Vector3(1, 1, 0), new Vector3(1, -1, 0), new Vector3(-1, -1, 0), new Vector3(-1, 1, 0) };
mesh.normals = new Vector3[] { new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1) };
mesh.triangles = new int[] { 0, 1, 2, 2, 3, 0 };
var entity = EntityManager.CreateEntity(typeof(LocalToWorld), typeof(Translation));
EntityManager.SetComponentData(entity, new Translation { Value = new float3(i * 2, 0, 0) });
var renderMesh = new RenderMesh();
renderMesh.mesh = mesh;
renderMesh.material = mat;
EntityManager.AddSharedComponentData(entity, renderMesh);
}
}
protected override void OnUpdate()
{
}
}
- Unity 2019.1.1f1 (Windows 10)
- Entities 0.0.12-preview.31
- Hybrid Renderer 0.0.1-preview.11
Enter playmode with the above TestSystem, and watch memory usage go up constantly (roughly 12MB per second on my end and proportional to the amount of meshes you are drawing). These memory won’t get freed up after exiting playmode either.
In one of my projects where I’m drawing thousands of unique meshes using RenderMesh, the Editor pretty much crashes after a couple minutes in Playmode. On the other hand, doing the same mesh generation with traditional MeshFilter and MeshRenderer does not leak memory.