How do you change the LODGroup Culled percentage via script

HI all,

How do you change the LODGroup Culled percentage via scripting (c#)

I can create an LODGroup and populate with geometry and set the percentage for the different LOD levels but I have no idea how you change the Culled percentage.

I cannot find anything in the documents either :confused:

Any help would be much appreciated

5 Answers

5

I have read through the documentation (Unity - Scripting API: LODGroup.SetLODs) but there is no mention of it there.

It seams odd that you canโ€™t set it via code.

Thanks

Hey veddcent, did you ever figure this out? Iโ€™m needing to do the same thing and canโ€™t find a way to set to culled.

From memory you set the percentage for the last group to 0. I'm not at my desk so cant confirm but if that's not it I'll check later.

โ€“

@jterry did you get this to work? A few more points: If you do not set the last LODGroup percentage to 0 then it will default to the built in culled group (i.e. nothing will render) but if you set you last LODGroup (i.e. LOD2) percentage to 0 then the culled group will no longer be there. Did that make sense?

โ€“

The way i set the cull percentage of the LODGroup is as follows:

I have 100% 66% 33% and want n% for cull

Lets say you want a 5% cull

so 100 x 1 / 20 = 5

if you want 10% cull

100 x 1 / 10 = 10, therefore [ LOD(1f / 10f, renderers); ]

                LODGroup lodGroup = go.GetComponent<LODGroup>();
                LOD[] lods = lodGroup.GetLODs();
                Renderer[] renderers = new Renderer[1];
                renderers[0] = meshRenderer[0];
                lods[lods.Length - 1] = new LOD(1f / 20f, renderers);
                lodGroup.SetLODs(lods);
                lodGroup.RecalculateBounds();

Thank you for providing more documentation on this ever than in the official docs.

โ€“

I can turn on LOD 1 immediately by using this code.

            LOD[] lods = lodGroup.GetLODs();
            // turn on LOD 1 immediately.
            lods[0].screenRelativeTransitionHeight = 1f;
            lods[1].screenRelativeTransitionHeight = 0f;
            lodGroup.SetLODs(lods);

I was searching it too, but then I found this:

LODGroup a;
a.ForceLOD(index);

so it can work even better in my case if I want override LOD sometimes. it also have set pass <0 to return it do default processing.