Search Unity

Editing Multiple LOD Prefabs at Once

Discussion in 'Editor & General Support' started by Leito, Jul 15, 2014.

  1. Leito

    Leito

    Joined:
    Apr 8, 2014
    Posts:
    37
    I have several prefabs that has LODs and I want to adjust the distance which the various models swap out. I want the all the prefabs to share the same swap out distance. At the moment, I'm resorting to going through each prefab to make the changes but it's extremely time consuming. Is there a way to do this en mass?
     
  2. sirio21

    sirio21

    Joined:
    Mar 11, 2013
    Posts:
    114
    Why they have different distances? When prefab is created by default has same percent between LOD.
    You can adjust your Bias value for share all LOD at once, no other method can be normalize percent LOD...
     
  3. Leito

    Leito

    Joined:
    Apr 8, 2014
    Posts:
    37
    Hrm, let me add a screen to help show what it is I'm asking.

    Is there a way to adjust the LOD percentange bar in the inspector for one prefab and have those values applied instantaneously to other prefabs?
    lod_bar.jpg
     
  4. azinicus

    azinicus

    Joined:
    Mar 20, 2016
    Posts:
    4
    This is a really ancient post, but I would also like to see if anyone has found a good way to do this because I have hundreds of small objects that I have LoDs on in a bigger prefab that I don't want to have to manually change the LoD on individually.
     
    hertz-rat and Walter_Hulsebos like this.
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I have the same issue, still cant work out how to edit multiple lods! Ridiculous really.
     
    Rickmc3280 and Walter_Hulsebos like this.
  6. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    Same issue... Ill bump this thread... If I find a solution ill bump it again.
     
  7. KingCeryn

    KingCeryn

    Joined:
    Feb 8, 2018
    Posts:
    158
    Lol well this was a sad thread to stumble on lol. currently changing every LOD group manually. Hoped there was a solution
     
  8. ainkiwi

    ainkiwi

    Joined:
    Oct 6, 2019
    Posts:
    4
    bump, same issue, please fix this... it's sad
     
  9. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    I think there is the possibility to make an editor script do this.
     
  10. crappygraphix

    crappygraphix

    Joined:
    Jan 14, 2009
    Posts:
    14
    Bringing this zombie back to life for anyone else who happens across it. This is brute force and works for my personal needs can be altered pretty easily. This code assumes LOD 0 -> LOD 3 -> Culled levels. Gives 100%, 15%, 10%, 5%, 1% camera distance set. Select the prefabs and run the menu command.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class MultiSetLOD : MonoBehaviour
    5. {
    6.   [MenuItem("Component/LOD/Set Default LOD Range", false, 0)]
    7.   static void DoSetDefaultLODRange()
    8.   {
    9.     var list = Selection.GetFiltered<GameObject>(SelectionMode.TopLevel);
    10.     foreach (var go in list)
    11.     {
    12.       var d = go.GetComponent<LODGroup>();
    13.       if (null != d)
    14.       {
    15.         var lods = d.GetLODs();
    16.         lods[0].screenRelativeTransitionHeight = 0.15f;
    17.         lods[1].screenRelativeTransitionHeight = 0.10f;
    18.         lods[2].screenRelativeTransitionHeight = 0.05f;
    19.         lods[3].screenRelativeTransitionHeight = 0.01f;
    20.         d.SetLODs(lods);
    21.         PrefabUtility.RecordPrefabInstancePropertyModifications(d);
    22.       }
    23.     }
    24.   }
    25. }
     
    Magnitude9, Dotti_H and Rodakai like this.
  11. KingCeryn

    KingCeryn

    Joined:
    Feb 8, 2018
    Posts:
    158

    goddamn you madman lol, ITS ALIVE. this worked properly for me too.
     
  12. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Making this a Frankenstein, This upgraded script does not care about the number of the LODs and sets the LOD dynamically. And also deals w/ culling (at 1%). Perhaps it could be useful! :)
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class MultiSetLOD : MonoBehaviour
    5. {
    6.     [MenuItem("Component/LOD/Set Default LOD Range", false, 0)]
    7.     static void DoSetDefaultLODRange()
    8.     {
    9.         var list = Selection.GetFiltered<GameObject>(SelectionMode.TopLevel);
    10.  
    11.         foreach (var go in list)
    12.         {
    13.             var d = go.GetComponent<LODGroup>();
    14.             if (null != d)
    15.             {
    16.                 var lods = d.GetLODs();
    17.                 int j = lods.Length-1;
    18.                 for (int i = 0; i < j; i++)
    19.                 {
    20.                     var x = ((i + 1f) / (j + 1f));
    21.                     Debug.Log(x);
    22.                     lods[i].screenRelativeTransitionHeight = 1f-x;
    23.                 }
    24.                 lods[lods.Length-1].fadeTransitionWidth = 0.01f;
    25.                 d.SetLODs(lods);
    26.                 d.RecalculateBounds();
    27.                 PrefabUtility.RecordPrefabInstancePropertyModifications(d);
    28.             }
    29.         }
    30.     }
    31. }
     
  13. Prot0Type

    Prot0Type

    Joined:
    May 18, 2017
    Posts:
    4
    A quick fix for some people might be an increse of the LoD Bias. Project settings>Quality>Level of Detail.
     
  14. Magnitude9

    Magnitude9

    Joined:
    Jul 11, 2017
    Posts:
    11
    Thank you for this!