Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current LOD level - LOD Group Unity

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.

like image 417
Bitelchús Avatar asked Sep 06 '25 19:09

Bitelchús


2 Answers

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).

like image 71
maros Avatar answered Sep 08 '25 10:09

maros


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.

like image 36
JulienH Avatar answered Sep 08 '25 09:09

JulienH