Hey, How would you calculate the size of a mesh in memory? The formula I have right now is something like: total = 0; total += 12 bytes //vertex total += 8 bytes * UVchannels // UVs total += 8 bytes // Vertex color total += 12 bytes // Normals total *= vertex count the result I get is always lower than what the memory profiler gives me, almost 2 times lower. What am I missing? thanks!
Maybe missing tangents (16 bytes), colors are only 4 bytes, and you’re missing 2*index count. Just off the top of my head. Will be some other stuff too
Right, actually my meshes don't have normals or tangent, but good to add it to the calculation! As for the index count, how does that work? I add it to the total before the vertex count multiplication? thanks!
It’s a separate list of data. You have calculated “vertexTotal”. You would do a new value called “indexTotal” and add the 2 together. IndexTotal = indexSize * indexCount. IndexSize is almost always 2, unless using 32 bit indices (if you’re unsure, then you’re using 16 bit)
Humm even with that I'm still exactly 2 times lower than what the profiler tells me. I mean I can just do *2 at the end of my calculation but that's no good! hehe
Interesting. Maybe it’s storing a cpu and gpu copy. Maybe there is a flag to prevent that if you don’t need to access the data from script. I’m not familiar with this area. This post looks related: https://forum.unity.com/threads/mesh-memory-usage.231164/ Maybe someone else knows more
Can't you use Profiler.GetRuntimeMemorySizeLong(mesh)? https://docs.unity3d.com/ScriptReference/Profiling.Profiler.GetRuntimeMemorySizeLong.html
I have been testing the GetRuntimeMemorySizeLong and the results differs a lot from the value shown in the inspector. I'm aware that memory size may vary from import size, but the differences are too big to the point GetRuntimeMemorySizeLong isn't usable for us in the Editor.
size0 = vertex and it's attributes size size1 = index buffer size in 16 or 32 bit (2 or 4 byte) size2 = empty size mesh total = (size0 + size1) * (readable ? 2 : 1) + size2