- Home /
Dynamic Mesh Collider - Optimization
So I've managed to create a mesh, alter its shape, and update its collision mesh every frame (right now its just a wave, but it works, it pushes cubes around).
My main thing now is that when the mesh gets too big, the updating slows down like crazy. The one line that slows the process is:
//Defined at start
private var meshCollide : MeshCollider; //later defined as the mesh collider
//on this object
private var clearMesh : Mesh; //stays empty
private var mainMesh : Mesh; //the mesh whose values I am adjusting
//Called in a "Update Mesh" function I have (called on each Update)
meshCollide.sharedMesh = clearMesh; //this line causes the delay,
//but allows the new mesh to be read properly
meshCollide.sharedMesh = mainMesh;
Is there a more efficient way of doing this?
EDIT: Well that was quickly resolved. I found that by using smaller "chunk" objects rather than one big one, the updating speed dramatically increased. Less memory operations, I would guess.
$$anonymous$$esh collision is just ridiculously expensive no matter which way you cut it. If you could approximate the wave action (or whatever future action you are planning) with complexes of convex colliders (boxes, spheres) it would be much easier for the physics engine to handle.
What I'm thinking is using this system to allow something like an explosion to deform the terrain, so in execution, this change would only happen once during those events. One way I found to optimize this was ins$$anonymous$$d of using one large object and having to change its entire mesh all at once, im using smaller "chunks", so when parts of them need to update, its a significantly faster memory operation. i was running 9 objects that made up the same area as the slower, larger one, and it was running significantly faster (from 0.3fps to 20fps), and that was with all of them updating every frame. Updating just one at a time runs easily at 45-60fps, and still allows nice collision.
Answer by TomNCatz · Sep 29, 2011 at 03:58 AM
You could also try swapping
meshCollider.sharedMesh = clearMesh;
for
meshCollider.sharedMesh.Clear();
This may clear it more efficiently for you.
Your answer
Follow this Question
Related Questions
How to make a dynamic mesh visible in Scene View 1 Answer
Updating Dynamic Mesh's Collider is Too Slow 1 Answer
How to make a mesh adjust its form around specific points 1 Answer
Why does Mesh.CreateVBO spike every few seconds on iOS Metal 0 Answers
Generating Mesh at runtime, vertex count different 0 Answers