Speeding up activation of new objects.

Here’s the setup.

I have an iOS project which stores very large models in SQLite files. While navigating the model, mesh data is pulled from the sqlite and applied to game objects which I am taking from a pool. When objects go out of range, the meshes are destroyed and the game objects are returned to the pool. All game objects have mesh colliders and everything is batching as static. All objects share the same material. The loading is all handled in a coroutine so you can be walking around while it’s loading stuff.

This all works really well, except there are certain cases where activating the pool objects with new geometry is slow, which I believe depends on the amount of stuff visible in the view (i.e. if I aim the camera at an area of the scene with no geometry during loading, there is a marked increase in speed). Loading the geometry from the file, updating the mesh and the colliders, is really fast. Drawing the object to the screen seems to be the hold-up.

I’ve tried disabling batching, assuming that the batching calculation when the object is activated in the scene is causing the delay, but unbatched FPS for my very large models is unacceptable. I’ve tried generating the objects without colliders, thinking that colliders might be the problem. Neither of these seemed to affect the issue of lag when the object is drawn in scene.

Can someone educate me as to what Unity is doing internally when you activate an object? Is there a step that I can cut out or back burner during my object setup so as not to incur a penalty to get the object in view?

I’ll answer my own question… Use the profiler! It tells you everything you need to know about where time is spent per frame. In my case, mesh colliders were killing me. Removing colliders altogether not only relieves you of the setup penalty, but also the per-frame physics calculation for the frame during loading. I really didn’t want to do an after-the-fact application of colliders though, so I made the objects use box colliders which are both faster to setup and faster to calculate per frame. It makes accurate selection a pain, so in that case I do a collider swap with a mesh collider to get a higher resolution for a selection.