I’m making a tool that involves deforming a mesh in runtime by displacing its vertices, deleting its vertices, and re-triangulating the mesh in 2D space but I’m running into performance issues with my code. Which data structures out there are best suited for this?
It seems you may have leaped from a performance issue to assuming it’s a data structures problem. It may well be, but prove it first, otherwise you’re wasting time doing work that won’t help.
DO NOT OPTIMIZE CODE JUST BECAUSE… If you don’t have a problem, DO NOT OPTIMIZE!
If you DO have a problem, always start by using the profiler:
Window → Analysis → Profiler
Failure to use the profiler means you’re just guessing, making a mess of your code for no good reason.
https://discussions.unity.com/t/841163/2
Notes on optimizing UnityEngine.UI setups:
According to the profiler, the functions I’m using to retrieve mesh data such as vertex data, edge data, and triangle data have high ms and I’m doing it by iterating through every vertex/triange/edge.
You are not supposed to work directly on the mesh data. You create a copy of the data (vertex array, uv array, color array etc.), modify that and then set the copy back to the mesh when you are done processing. Same applies for textures.
If you need to “constantly” modify the mesh data and it is large you should try to break it up into distinct parts (chunks) which are processed on demand (so you only upload data which has changed and not ALL of it).
The reason this is slow is, that meshes exist in GPU memory of the graphics card and getting them back to CPU for modification is slow. Depending on what you want to do you could also check wether compute shaders could do this stuff directly on GPU so you don’t need to “download” it.
If you would elaborate on what you want/need to do the advise could be more specific. And usually people post code to be discussed in the Scripting subforum ;).