Adding mesh to UI camera?

I have a mesh that I’d like to be rendered only by the UI camera (it should overlay other things and has no position relative to rest of the scene, only to the UI). Think something like this:

Has anyone done something like this? The other option would be to set up my own camera and render texture, render it there, and then draw the render texture as a sprite, but that seems like a ton of work as well as a performance cost, so if I can reuse any existing UI rendering infra, I’m all for that.

In case anyone has the same question, I found two ways. The first is the camera thing mentioned above, not actually as tricky as I thought it would be, but mostly undocumented:

public MapMenu()
{
    _input = Inject.InputCore;
    _mesh = MinimapMeshGenerator.getMesh(Inject.BuildingManager.getBuilding(), 0);

    _mmDisplayObj = new GameObject("#MinimapDisplay") {layer = 5};
    MeshFilter mf = _mmDisplayObj.AddComponent<MeshFilter>();
    mf.sharedMesh = _mesh;
    MeshRenderer mr = _mmDisplayObj.AddComponent<MeshRenderer>();
    mr.shadowCastingMode = ShadowCastingMode.Off;
    mr.receiveShadows = false;
    mr.sharedMaterial = Inject.UiRoot.prefabs.minimapMaterial;
    _mmDisplayObj.transform.position = new Vector3(0, 0, 0);

    Camera mainCam = Inject.MainCamera.camera;
    _mmCameraObj = new GameObject("#MinimapCamera");
    _mmCamera = _mmCameraObj.AddComponent<Camera>();
    _mmCamera.CopyFrom(mainCam);
    _mmCamera.orthographic = true;
    _mmCamera.orthographicSize = 50;
    _mmCamera.cullingMask = 1 << 5;
    _mmCameraObj.transform.position = new Vector3(0, 0, -100);
    _mmCamera.clearFlags = CameraClearFlags.Nothing;
    _mmCamera.depth = mainCam.depth + 1;
}

Camera trick will not work in HDRP, you must render to texture.

If you want closer integration with the UI, you can override UnityEngine.UI.Graphic, which may be easier or not depending on your needs. That’s what I ended up doing – just extend UnityEngine.UI.Graphic and override the OnPopulateMesh(VertexHelper) method.