What do I add to the LOD Renderer in MonoBehaviour?

Hi, I have a script that generates meshes for rocks procedurally. This all works great, I can create endless random rocks that are all different. Now I am trying to create LOD groups for each of these rocks for optimisation purposes (obviously!). I know how to use the LOD Group component in the inspector, but I can’t seem to get a grip on how to add my meshes to it in code. My main problem is that I can’t figure out what the hell the LOD renderer wants me to add. It’s not a mesh, a meshFilter, a meshRender, the GameObject that contains the mesh, so what is it? Here’s a sample of my code:

GameObject sphere = new GameObject ("ICOSphere", typeof(MeshRenderer), typeof(MeshFilter), typeof(LODGroup));
sphere.transform.position = new Vector3 (2, 2, -2);

LODGroup lodGroup = sphere.GetComponent<LODGroup> ();
			
Renderer[] renderer = new Renderer[1];
renderer[0] = sphere.GetComponent<MeshRenderer>();

LOD[] lods = new LOD [3];
lods [0] = new LOD (0.5f, renderer);

lodGroup.SetLODS (lods);

the line:

renderer[0] = sphere.GetComponent<MeshRenderer>(); 

is where I’m currently struggling. although unity does infact allow me to use MeshRenderer here, it doesn’t seem to do anything. I would have expected this to either be a mesh or a gameObject (because you drag a gameObject into the LOD when you do it in the inspector).

I’m so confused. And my script contains the word LOD more times than I can make sense of it! :S

Cheers in advance for any pointers!

Pete

any ideas?

The answer comes late but I struggled with this myself since the official documentation is a bit too brief on this.

The MeshRenderer you provide for each LOD level by invoking LODGroup::SetLODs are the Renderer instances of game objects representing the individual LOD levels. The LOD mechanism simply sets the Renderer.isVisible flags regarding the calculated normalized covered screen-height of the object.

The game objects that represent each individual LOD level I have parented to lodGroup.transform and named those according the naming convention (e.g. LOD 0, LOD 3 etc).