- Home /
Efficient visualization of 100000+ simple objects
Hi everybody,
I need to visualize a set of some 100 thousand objects: Simple cubes (same material, same size, movable, no physics).
Instantiating 125000 GameObjects from a single prefab takes a significant amount of time (3 nested for loops, C#) and the framerate drops to ~1 when the entire grid of cubes is visible. Dynamic batching already reduces the drawcalls to around ~150.
Any suggestions on how to tackle this?
Thanks for your suggestions ;
rev
You write "movable." Do you mean independently movable or movable as a whole? Are any chunks of them moved together?
If you go with the procedural option, and are using Unity 4, you should use the new `$$anonymous$$esh.$$anonymous$$arkDynamic` method.
Answer by numberkruncher · Feb 11, 2013 at 04:39 PM
Procedural Solution:
I would seriously consider presenting these objects using a procedurally generated mesh instead of using 100,000's of individual game objects. I would represent the objects using a chunked data structure and spread the procedural mesh across multiple chunks. This would greatly reduce the number of objects (because you would essentially just have one game object for each chunk).
For example,
YourGrid [ ProceduralGridBehaviour ]
--> Chunk [ ProceduralChunkBehaviour + MeshFilter + MeshRenderer ]
--> Chunk [ ProceduralChunkBehaviour + MeshFilter + MeshRenderer ]
--> Chunk [ ProceduralChunkBehaviour + MeshFilter + MeshRenderer ]
Personally I would avoid using colliders for said objects because the performance spike of adding and removing colliders at runtime in scenarios like this can be extremely costly. If you are creating a Minecraft-style voxel game then there are often better ways to simulate collision.
Pooled Solution:
Another option might be to keep a data structure that identifies which objects should be where and their current state. You could then spawn the blocks that are either a) visible or b) in proximity to reduce the overall number of objects present at any given time. You would generally utilise a pooling solution to both recycle objects and avoid instantiations at runtime.
PoolManager by Path-o-logical Games is a fantastic pooling solution and is certainly worth mentioning.
Thanks for your quick answer - I like the idea of having individual chunks since the underlying data set is made up of semantic groups anyway.
I'll try the procedural approach using $$anonymous$$esh.$$anonymous$$arkDynamic (thanks numberkruncher) and let you know the results.
While implementing the procedural approach I hit the 64k vertex limit per mesh, worked around it by using multiple meshes.
The visualization of 128000 cubes is now fluid :)
Thanks again for your helpful advice.
Your answer
Follow this Question
Related Questions
Set Precision of Scientific Notation 1 Answer
Large number of objects problem 1 Answer
how do I access these game objects by number? 2 Answers
Camera looking through objects when touching 1 Answer
Preventing objects from shoved 0 Answers