Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Attempting to force a LOD outside the number available LODs

Discussion in 'Scripting' started by dburden1, Jan 25, 2016.

  1. dburden1

    dburden1

    Joined:
    Jan 29, 2015
    Posts:
    19
    For some reason in this code I'm getting this runtime warning on line 6 of the code below:
    Code (CSharp):
    1. LODGroup lodGroup = obj.GetComponentInChildren<LODGroup>();
    2. if (lodGroup != null)
    3. {
    4.     for (int lod = 0; lod < lodGroup.lodCount; ++lod)
    5.     {
    6.         lodGroup.ForceLOD(lod); // Warning happens here
    7.         doSomething();
    8.         yield return null;
    9.     }
    10.     lodGroup.ForceLOD(-1);
    11. }
    It seems like this should never happen provided that LODGroup.lodCount is returned correctly (which is a built in get-only property). Does lodCount also account for the culled LOD, and so the warnings are happening when trying to force the culled LOD? It doesn't say in the docs.

    It's also worth mentioning that we aren't procedurally building LODGroups either, so the lodCount shouldn't change between iterations of the coroutine.
     
    Last edited: Jan 26, 2016
  2. dburden1

    dburden1

    Joined:
    Jan 29, 2015
    Posts:
    19
  3. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    235
    Did you fix this? I'd like to be able to turn off the entire LOD without having to disable the LOD, then disable the children. I assumed I could do this by setting LOD to 99999 or 1-more-than-the-number-of-lods.
     
  4. pophl

    pophl

    Joined:
    Mar 3, 2017
    Posts:
    14
    Did anyone solve this? We get the same error spamming when we call this

    Code (csharp):
    1.  
    2. static public void ForceMaxLOD(GameObject objectRoot)
    3. {
    4.    foreach(LODGroup lodGroup in objectRoot.GetComponentsInChildren<LODGroup>())
    5.    {
    6.        if (lodGroup.lodCount > 0)
    7.        {
    8.            lodGroup.ForceLOD(0);
    9.        }
    10.    }
    11. }
    12.  
     
  5. TOES

    TOES

    Joined:
    Jun 23, 2017
    Posts:
    134
    Same here. Looks like a bug in Unity. It is annoying because just printing out the error causes a lag, and I have tens of thousands of objects that needs to do this