`NullReferenceException: Object reference not set to an instance of an object
Planet.GenerateMesh () (at Assets/Planet.cs:66)
Planet.GeneratePlanet () (at Assets/Planet.cs:49)
PlanetEditor.OnInspectorGUI () (at Assets/editor/PlanetEditor.cs:17)
UnityEditor.UIElements.InspectorElement+<CreateIMGUIInspectorFromEditor>c__AnonStorey1.<>m__0 () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:501)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
Relevant code (plus context. I tried to put the line numbers in but it messes with formatting, rip):
Planet.cs:
lines 47-51
public void GeneratePlanet() {
Initialize();
GenerateMesh();
GenerateColours();
}
void GenerateMesh() {
foreach (TerrainFace face in terrainFaces) {
face.ConstructMesh();
}
}
public void ConstructMesh() {
Vector3[] vertices = new Vector3[resolution * resolution];
int[] triangles = new int[(resolution - 1) * (resolution - 1) * 6];
int triIndex = 0;
for (int y = 0; y < resolution; y++) {
for (int x = 0; x < resolution; x++) {
int i = x + y * resolution;
Vector2 percent = new Vector2(x, y) / (resolution - 1);
Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
Vector3 pointOnUnitSphere = pointOnUnitCube.normalized;
vertices[i] = shapeGenerator.CalculatePointOnPlanet(pointOnUnitSphere);
if (x != resolution - 1 && y != resolution - 1) {
triangles[triIndex] = i;
triangles[triIndex + 1] = i + resolution + 1;
triangles[triIndex + 2] = i + resolution;
triangles[triIndex + 3] = i;
triangles[triIndex + 4] = i + 1;
triangles[triIndex + 5] = i + resolution + 1;
triIndex += 6;
}
}
}
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
}
I'm only at the end of EP02, but I should be able to change the color, radius, and resolution of the sphere in real time. This is the error I get when I try to change the resolution. I haven't even tried to change radius or color yet. This error has persisted in a few forms throughout EP01 and EP02 (I have not once been able to change resolution with the slider in the inspector). I've included my entire assets folder in case you want to check it out for a solution for me. Thanks in advance!
Assets.zip