Is there any way to find out current LOD level of LODGroup?

Hi,

Is there any way to find out current LOD level of LODGroup? I,m trying to use unity 3.5 LODGroup level to change my script behavior in different distances.

Thanks in advance.

I’m looking to do a similar thing, I want to optimise a whole bunch of stuff around my complex objects based off the current LOD. Rather than looping through the renderers all the time you can use the OnBecameVisible and OnBecameInvisible events from a script attached to the primary renderer objects for each LOD level.

using UnityEngine;

public class LODController : MonoBehaviour 
{
    public int LODLevel;

    void OnBecameVisible()
    {
        Debug.Log("LOD Level " + LODLevel + " became visible");
    }

    void OnBecameInvisible()
    {
        Debug.Log("LOD Level " + LODLevel + " became invisible");
    }
}

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 every LOD subobjects.)

I uploaded the solution here: EditorScripts/Scripts/Utility/Editor/LODExtendedUtility.cs at master · JulienHeijmans/EditorScripts · GitHub

It is mostly code that I took from here: https://github.com/Unity-Technologies/AutoLOD/blob/master/Scripts/Extensions/LODGroupExtensions.cs I just removed what was not necessary, and added 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.

Did you ever find out how to do that? I have been looking for a solution, however still no luck.

If somebody stumbles on this and doesn’t find the link instantly, there is a workaround at:
http://stackoverflow.com/questions/37755510/current-lod-level-lod-group-unity

With code:

LODGroup lodGroup = obj.GetComponent();
 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); 
         }
     }
 }