I'm having trouble leading with LOD Group, because I want to know which is the current active LOD level that I see in the screen. I only can access to the percentage with
GameObject.GetComponent<LODGroup>().GetLODs()[size].screenRelativeTransitionHeight;
Someone knows how to solve this? Thanks in advance.
Searching through the answers answers.unity3d.com, I came to this: http://answers.unity3d.com/questions/684467/find-the-lod-step-which-is-currently-used.html
LODGroup lodGroup = obj.GetComponent<LODGroup>();
if (lodGroup != null)
{
Transform lodTransform = lodGroup.transform;
foreach (Transform child in lodTransform)
{
var renderer = child.GetComponent<Renderer> ();
if (renderer != null && renderer.isVisible)
{
Debug.Log("This LODlevel is used: " + child.name);
}
}
}
You can find out which LOD level is currently active by looking into the names of children GameObjects Renderers which are currently visible (visible on the screen).
I had the same issue, and finally found out a solution that really works. (The renderer.isVisible is not updated often enough to be reliable, unfortunately, and I did not want to add additionnal components on ever LOD subobjects.)
I uploaded the solution here: https://github.com/JulienHeijmans/EditorScripts/blob/master/Scripts/Utility/Editor/LODExtendedUtility.cs
It is mostly code that I took from here: https://github.com/Unity-Technologies/AutoLOD/blob/master/Scripts/Extensions/LODGroupExtensions.cs I just rmeoved what was not necessary, and addod other utility functions that I had to use often.
It has been made to be used as an in-editor utility script, but the math to get the currently visible LOD level is there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With