Any idea how to use PreviewRenderUtility ?

I was coding and I typed “preview…” and saw PreviewRenderUtility. A public class with function that seem to allows up to now quickly draw our own preview windows in the unity Editor …
But it has not been documented yet so attempts to make it work are hit and miss.

Anyone used this before and got it working ?
Could you how me how it is used ?

If I am correct it should allows us to finally do things like this easily .90922-prev.png

@DMDev I noticed code for this after viewing this Unite talk here:

You can see them talk about asset previews around the 8:00 minute mark. This is the code they use:

PreviewRenderUtility renderUtility = new PreviewRenderUtility();

void OnGUI(){
Rect rect = new Rect(40,200,200,200);
renderUtility.BeginPreview(rect, “”);
renderUtility.DrawMesh(previewModel.mesh,, Quaternion.identity, previewModel.material,0);

Just in case somebody stomps here looking for some info on PreviewRenderUtility, I just gathered the following code from here and there to draw a prefab using it:

    void BeginDraw(Rect r)
        if (prevRenderer == null)
            prevRenderer = new PreviewRenderUtility(); = camPosition;, Vector3.up); = 30;

        prevRenderer.lights[0].intensity = 0.5f;
        prevRenderer.lights[0].transform.rotation = Quaternion.Euler(30f, 30f, 0f);
        prevRenderer.lights[1].intensity = 0.5f;

        prefabTransform.SetTRS(prefabTranslation, Quaternion.Euler(prefabRotation), prefabScale);

        prevRenderer.BeginPreview(r, GUIStyle.none);

    void EndDraw(Rect r)
        bool fog = RenderSettings.fog;

        Texture texture = prevRenderer.EndPreview();
        GUI.DrawTexture(r, texture);

    public void DrawRenderPreview()
        if (prefab != null)
            MeshFilter[] meshFilters = prefab.GetComponentsInChildren<MeshFilter>();
            for (int i = 0; i < meshFilters.Length; i++)
                if (meshFilters*.sharedMesh)*

MeshRenderer meshRenderer = meshFilters*.gameObject.GetComponent();*
for (int j = 0; j < meshFilters*.sharedMesh.subMeshCount; j++)*
if (meshRenderer != null)
prefabTransform * meshRenderer.transform.localToWorldMatrix,

private void OnGUI()
Rect r = new Rect(0.0f, 0.0f, position.width, position.height);


This code will draw a GameObject referenced in the prefab variable, and it’s part of an EditorWindow. I’m sorry I have not enough time to prepare the full working class, but the code is pretty self explanatory, and you can have it working in no time.