Tried to implement some of the things i have learned, but got stuck on with some error referring to HD pipeline.
Might be that i introduced some bug with my script, but when i compile in VS 2019 it donât complain. So i am not sure were i should start troubleshoot.
If anyone could point me in the right direction that would be nice
using unity version 2019.3.3f1
Error message:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Rendering.HighDefinition.FrameSettingsHistory+MinimalHistoryContainerâŚctor () (at Library/PackageCache/com.unity.render-pipelines.high-definition@7.1.8/Runtime/RenderPipeline/Settings/FrameSettingsHistory.cs:59)
UnityEngine.Rendering.HighDefinition.FrameSettingsHistoryâŚcctor () (at Library/PackageCache/com.unity.render-pipelines.high-definition@7.1.8/Runtime/RenderPipeline/Settings/FrameSettingsHistory.cs:67)
Rethrow as TypeInitializationException: The type initializer for âUnityEngine.Rendering.HighDefinition.FrameSettingsHistoryâ threw an exception.
UnityEngine.Rendering.HighDefinition.DebugDisplaySettings.RegisterCamera (UnityEngine.Rendering.HighDefinition.IFrameSettingsHistoryContainer container) (at Library/PackageCache/com.unity.render-pipelines.high-definition@7.1.8/Runtime/Debug/DebugDisplay.cs:899)
UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData.RegisterDebug () (at Library/PackageCache/com.unity.render-pipelines.high-definition@7.1.8/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs:436)
UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData.OnEnable () (at Library/PackageCache/com.unity.render-pipelines.high-definition@7.1.8/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs:469)
The script
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
public class TerrainGenerator : MonoBehaviour
{
GameObject terrain;
Mesh terrainMesh;
Vector3[] vertices;
int[] triangles;
Vector2[] uvs;
public int xVertices = 20;
public int zVertices = 20;
MeshFilter meshFilter;
// meshFilter = meshObject.AddComponent<MeshFilter>();
void Start()
{
terrain = new GameObject("Empty");
terrainMesh = new Mesh();
terrain.AddComponent<MeshFilter>();
terrain.AddComponent<MeshRenderer>();
terrainMesh = terrain.GetComponent<MeshFilter>().mesh;
TileData tiledata = new TileData(xVertices, zVertices);
meshFilter.mesh = tiledata.CreateMesh();
CreatingTile();
}
void CreatingTile()
{
TileData tiledata = new TileData(xVertices, zVertices);
// vertices = new Vector3[(xVertices + 1) * (zVertices + 1)];
for (int i = 0, z = 0; z <= zVertices; z++)
{
for (int x = 0; x <= xVertices; x++)
{
float y = Mathf.PerlinNoise(x * .3f, z * .3f) * 2f;
tiledata.vertices[i] = new Vector3(x, y, z);
i++;
}
}
//triangles = new int[xVertices * zVertices * 6];
int vert = 0;
int tris = 0;
for (int z = 0; z < zVertices; z++)
{
for (int x = 0; x < xVertices; x++)
{
tiledata.triangles[tris + 0] = vert + 0;
tiledata.triangles[tris + 1] = vert + xVertices + 1;
tiledata.triangles[tris + 2] = vert + 1;
tiledata.triangles[tris + 3] = vert + 1;
tiledata.triangles[tris + 4] = vert + xVertices + 1;
tiledata.triangles[tris + 5] = vert + xVertices + 2;
vert++;
tris = tris + 6;
}
vert++;
}
//Creating UVS
//uvs = new Vector2[vertices.Length];
for (int i = 0, z = 0; z <= zVertices; z++)
{
for (int x = 0; x <= xVertices; x++)
{
tiledata.uvs[i] = new Vector2((float)x / xVertices, (float)z / zVertices);
//uvs[i] = new Vector2((float)x / xVertices, (float)z / zVertices);
i++;
}
}
Debug.LogWarning("count vertices = " + tiledata.vertices);
Debug.LogWarning("count triangles = " + tiledata.triangles);
Debug.LogWarning("count uvs = " + tiledata.uvs);
}
public class TileData
{
public Vector3[] vertices;
public int[] triangles;
public Vector2[] uvs;
public TileData(int xVertices, int zVertices)
{
vertices = new Vector3[xVertices * zVertices];
uvs = new Vector2[vertices.Length];
triangles = new int[xVertices * zVertices * 6];
}
public Mesh CreateMesh()
{
Mesh mesh = new Mesh();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.uv = uvs;
mesh.RecalculateNormals();
return mesh;
}
}
}