private IEnumerator WriteTex(RenderTexture rt, bool alpha) { //Pull texture off of GPU var req = AsyncGPUReadback.Request(rt, 0, 0, rt.width, 0, rt.height, 0, 1, alpha ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat); while (!req.done) { yield return(null); } RenderTexture.ReleaseTemporary(rt); string path = GetCaptureFilename(); LogScreenshotMessage("Writing rendered screenshot to " + path.Substring(Paths.GameRootPath.Length)); //Write raw pixel data to a file //Uses pngcs Unity fork: https://github.com/andrew-raphael-lukasik/pngcs if (alpha) { using (var buffer = req.GetData <Color32>()) yield return(PNG.WriteAsync(buffer.ToArray(), req.width, req.height, 8, true, false, path)); } else { using (var buffer = req.GetData <Color>()) yield return(PNG.WriteAsync(buffer.ToArray(), req.width, req.height, 8, false, false, path)); } }