Hi,
The platform tutorial mentions that in very large scenes, its useful to hide far objects, because culling them out each frame is expensive.
I tried implementing this method in the following way :
- Created layers for my objects and 3 visibility layers.
- Created three children on the camera, giving them each of the visibility layer, with a sphere collider of different sizes.
- Used the collision matrix to control which object layers become visible at which distance
- Attached a script to the spheres that enables object renderers on OnTriggerEnter, and disables the renderers in OnTriggerExit.
Also, in the beginning of the scene, all objects have their renderers disabled.
So, when an object enters its visible range, I’ll get the OnTriggerEnter and enable its renderer, and the parallel thing when leaving the range.
The problem is : I need to attach a rigidbody to the spheres or I don’t get the trigger messages. When I do that, my performance gets a huge hit - Physics.Simulate takes about 50% of the frame time (up from 6-8% before this technique).
I tried doing it the other way around - attaching rigidbodies to the objects in the scene, but then I didn’t get the trigger events in the right places. (According to Unity - Manual: Mesh collider component reference I should get triggers, but I don’t)
Does anyone know if this trick can be performed in large scenes without paying a big performance hit in Physics.Simulate? Are there any other methods?