In HDRP using Screen Space - Overlay Canvas, How can I edit UI.Image vertices at runtime?
I am attempting to create a minimap in HDRP by using a Image in a screen space - overlay canvas, I would like to manipulate the vertices of the UI.Image mesh at runtime. Most examples i have come across utilise a OnPopulateMesh(VertexHelper vh) override.
Problem with the below, is as soon as I call the CanvasRenderer.SetMesh() method, unity crashes. The goal is to skew and rotate the Image vertices at runtime to simulate a minimap compass.
Any advice is greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Test : Image
{
Mesh m;
CanvasRenderer canvasEle;
void Update()
{
canvasEle = transform.GetComponent<CanvasRenderer>();
m = canvasEle.GetMesh();
if (m != null)
{
Vector3[] verts = new Vector3[m.vertices.Length];
for(int i = 0; i < m.vertices.Length; i++)
{
verts[i] = m.vertices[i];
}
verts[0].x = (m.vertices[0].x + 50);
m.vertices = verts;
m.RecalculateBounds();
}
canvasEle.SetMesh(m);
}
}