I’m working on a game that involves a lot of objects that I need to dynamically remove and add to the scene and I was wondering if its more efficient for the CPU/GPU to disable objects that I don’t want rendered or to clip them using a custom shader? For example if this pixel is a certain distance from the player don’t render it. As of right now I’ve been disabling objects that I need entirely removed and writing shaders for objects I need partially rendered, but I’m wondering if I should even be disabling the other objects and not just clipping them using a shader if that’s better performance-wise.
If you need the components to still run their logic, you can’t disable the GameObject.
Disabling a GameObject is also more expensive than simply setting the enabled property of its renderer(s). This will hide the object but its scripts keep running. For purely scripted hiding of objects, this is the way to use.
But Unity already has a system to hide meshes based on distance: LOD (Level of Detail). You can simply use an invisible (or null/none) mesh for LOD 1 for any mesh in order to hide that mesh when its distance passes the LOD1 threshold.
Also you may want to look into custom occlusion culling. There’s really no need to create or modify a shader.
1 Like