- Home /
LOD Error on Unity's own Example script
I get two errors in 2018.3 from Unitys own example script in the LODGroup.SetLODs page..
The errors I get are: 1: 'LOD' does not contain a constructor that takes 2 arguments 2: Cannot convert from 'LOD[]' to 'UnityEngine.LOD[]'
Any thoughts on why? I searched a bunch and can't seem to find a solution.
using UnityEngine;
using System.Collections;
public class LODExample : MonoBehaviour
{
public LODGroup group;
void Start()
{
// Programmatically create a LOD group and add LOD levels.
// Create a GUI that allows for forcing a specific LOD level.
group = gameObject.AddComponent<LODGroup>();
// Add 4 LOD levels
LOD[] lods = new LOD[4];
for (int i = 0; i < 4; i++)
{
PrimitiveType primType = PrimitiveType.Cube;
switch (i)
{
case 1:
primType = PrimitiveType.Capsule;
break;
case 2:
primType = PrimitiveType.Sphere;
break;
case 3:
primType = PrimitiveType.Cylinder;
break;
}
GameObject go = GameObject.CreatePrimitive(primType);
go.transform.parent = gameObject.transform;
Renderer[] renderers = new Renderer[1];
renderers[0] = go.GetComponent<Renderer>();
lods[i] = new LOD(1.0F / (i + 1), renderers);
}
group.SetLODs(lods);
group.RecalculateBounds();
}
void OnGUI()
{
if (GUILayout.Button("Enable / Disable"))
group.enabled = !group.enabled;
if (GUILayout.Button("Default"))
group.ForceLOD(-1);
if (GUILayout.Button("Force 0"))
group.ForceLOD(0);
if (GUILayout.Button("Force 1"))
group.ForceLOD(1);
if (GUILayout.Button("Force 2"))
group.ForceLOD(2);
if (GUILayout.Button("Force 3"))
group.ForceLOD(3);
if (GUILayout.Button("Force 4"))
group.ForceLOD(4);
if (GUILayout.Button("Force 5"))
group.ForceLOD(5);
if (GUILayout.Button("Force 6"))
group.ForceLOD(6);
}
}
Answer by xxmariofer · Feb 09, 2019 at 09:48 PM
well thats extrange, can you change
LOD[] lods = new LOD[4];
to
UnityEngine.LOD[] lods = new UnityEngine.LOD[4];
in case any class is giving conflict? whats your unity version?
Hey, thanks for your reply, your answer did get rid of one of the errors. So thank you. I’m using Unity 2018.3.3f1.
The second error is still there which is “'LOD' does not contain a constructor that takes 2 arguments”. This is strange to me because according to the docs it does take 2 arguments?
but is an error when the game is running? are you 100% sure you dont have a LOD class overriding the unityengine class?
Well, that was it!! I had this other LOD script that was interfering. Thank you, I was scratching my head for a while there!
BTW - I've been a member since 2014, and I've only posted several questions over the years, you're the first to ever reply to me. So I mean it when I say I greatly appreciate your help!
Your answer
![](https://koobas.hobune.stream/wayback/20220612191437im_/https://answers.unity.com/themes/thub/images/avi.jpg)