I'm getting the error "ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame."
However this action works perfectly fine for my purposes regardless of the error. The texture I want gets set and the debugging screenshot is fine too. I know I'm supposed to run read pixels in a coroutine where I wait for the end of frame but there appears no way to do this in playmaker.
using UnityEngine;
using System;
using System.Collections;
namespace HutongGames.PlayMaker.Actions {
[ActionCategory("MyActions")]
public class screenTexture : FsmStateAction {
public FsmRect screenArea;
public FsmTexture screenshot;
public override void OnEnter() {
int width = Mathf.CeilToInt (screenArea.Value.width);
int height = Mathf.CeilToInt (screenArea.Value.height);
Texture2D tex = new Texture2D (width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels (screenArea.Value, 0, 0);
tex.Apply ();
byte [] bytes = tex.EncodeToPNG ();
// For testing purposes, also write to a file in the pictures folder
System.IO.File.WriteAllBytes (Environment.GetFolderPath (Environment.SpecialFolder.MyPictures) + "/SavedScreen.png", bytes);
screenshot.Value = tex;
}
}
}
Can I suppress the error somehow? Or is there another way to get the texture from a screen area like I want?