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 :/
Any help would be much appreciated
Answer by veddycent · Nov 12, 2017 at 06:52 PM
I have read through the documentation (https://docs.unity3d.com/ScriptReference/LODGroup.SetLODs.html) but there is no mention of it there.
It seams odd that you can't set it via code.
Thanks
Answer by jterry · Apr 10, 2018 at 05:34 PM
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?
Answer by GXMark · Aug 23, 2018 at 10:16 PM
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.
Answer by TaehoonYoon · Sep 18, 2020 at 06:33 AM
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);
Answer by Ava42 · Dec 26, 2021 at 05:44 PM
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.