- Home /
How do you set mesh.indexFormat?
I don't believe in stupid questions, but, this one could be highly simplistic...;^)
I see with Unity 2017 the mesh indexFormat property can be set to UInt32 to increase the maximum number of vertices allowed in a mesh. It isn't too clear in the docs. How do you actually set that in a C# script?
Thanks!
Answer by saschandroid · Jan 19, 2018 at 08:15 AM
Mesh mesh = new Mesh();
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
Thanks. The Unity manual doesn't make this very clear.
$$anonymous$$h, I think it's fine - I'm just afraid sometimes that it's outdated because there is so many new Unity versions. :)
Unity 2019 manual says that the default is UInt16. Is this true? https://docs.unity3d.com/ScriptReference/$$anonymous$$esh-indexFormat.html
Uhm, yes. Unity always used 16 bit index buffers in the past. There wasn't even an option to change it. That's why we were limited to 64k vertices per mesh. Now since they added support for 32 bit index buffers a mesh can have up to 4 billion (short scale or 4 milliard in the long scale). However the default is still 16 bit. Both to be backwards compatible and to be more efficient since 16 bit index buffers are just half the size. When importing meshes inside Unity with more than 64k vertices Unity should automatically create a mesh with a 32 bit index buffer.
Hey Bunny83. Thanks.
I'm creating my meshes procedural:
$$anonymous$$esh mesh = new $$anonymous$$esh();
Vector3[] meshVertices = vertices.ToArray();
I was pretty sure I created a mesh with > 64k vertices yesterday and was not forced to set the IndexFormat to UInt32 - $$anonymous$$aybe I was wrong and the vertice were less. :) That problably has to be the case (Unity 2019).
Best wishes, SG
Your answer
Follow this Question
Related Questions
How do I get rid of intersecting vertices between two gameobjects? 0 Answers
Edit SkinnedMeshRenderer 1 Answer
ECS RenderMesh not visible 1 Answer