- Home /
Gizmos.DrawCube bug? Doesn't like lots of calls.
I've noticed that whenever Gizmos.DrawCube is used a lot, it stop drawing cubes and starts drawing a bunch of random lines. See screen shots below. Through some testing I've discovered that the magic limit is 1365. For example, if I make a grid of 10x100 cubes (1000 total), they all draw correctly. But if I try to draw a 10x100 grid of cubes, they start getting messed up. Is this a bug?
(10x100 cubes, everything's okay)
(100x100 cubes, barf...)
Do you get any error messages that come along with this?
By the way, in the mean time I've avoided the problem by using DrawWireCube ins$$anonymous$$d of DrawCube.
Answer by Berenger · May 16, 2012 at 04:37 AM
This might be due to Unity's max vertex count per object, which is 2^16 (65536) and 100*100 cubes is 10 000 * 8 vertex, 80 000. If this is incorrect, I'll move my answer to the comments.
That actually makes sense. The lines seem to be pointing to other vertices than the ones they should, suggesting that after a point the indices are getting messed up. Good thought. Any way to break gizmos out into multiple objects to avoid this problem?
I'm not sure if unity is packing every gizmos in the scene into one mesh or if it's only for one object drawing gizmos. I though about that because of Aron Granberg's path finding tools, where the grid was all messed up when you had too many nodes. $$anonymous$$aybe he found a way around.
Yeah, I've noticed that with the same path finding extension. =P I finally just commented out the lines in that where the unwalkable nodes were drawn because it was driving me crazy.
The gizmos are pertty sure all packed into one mesh, otherwise you would have real performance issues.
Btw a cube needs 24 vertices since you need a seperate vertex normal for each face. So 4 vertices and 2 triangles per face. One cube needs 36 indices (6faces == 12 triangles)
Unity's mesh class is actually clamped to exactly 65000 indices. That would be ~1500 cubes, but don't forget all the other default gizmos ;)