How to properly handle mesh creation

All right, I’ve been circling around this issue long enough. I’m finally ready to ask directly, how are we supposed to be creating mesh?

Unity seems to think we really want to use shared mesh. But I don’t want to use shared mesh because I actually want every instance of that object to have its own mesh. Then I become insecure because I don’t know if what I’m doing really is leaking mesh or that error/warning doesn’t apply to this case. To make things more complicated, I want to create these meshes before runtime too! My current project is clearly leaking memory though, so that’s not a good sign.

I’ve read countless forum posts on the subject throughout the years but I mostly just wanted to do something quickly and needed a fast solution. Now I need a firm ground.

Help me, Unity forums. You’re my only hope. Help me clear up this mess.

Use the profiler - it’s like five times as important as it normally is when you’re constructing meshes. If you see a bunch of GC being allocated, then you need to work on array management (which is…tricky). I’ve always ignored that leaking mesh message, and it hasn’t hurt me yet (I don’t care so much about performance in the editor, TBH).

Exactly. I can make it not leak by changing how I do it. Ironically, this way causes leak error messages (the red ones but it still compiles and runs fine). The choice between no leak error message with leaks and leak error messages without leaks is an easy one, but I still feel there has to be a right way of doing this.