- Home /
Wait for Texture.ReadPixels
Hi. How to a stop script execution until texture is read? TextureRectangle = new Rect (0, 0, Screen.width,Screen.height); Texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); Texture.ReadPixels(TextureRectangle, 0, 0, false); Texture.Apply();
Here needs something like this Wait for all pixels read.
Because this give me a wrong color.
InputColor = Texture.GetPixel((int)TextureCoords.x, (int)TextureCoords.y);
Answer by Priyanka-Rajwanshi · Jun 28, 2020 at 10:39 AM
@MotionTracker The best way is to call the above line of code in OnPostRender() function.
Alternatively, use a coroutine to Wait till the end of frame.
IEnumerator ReadTexture(){
yield return new WaitForEndOfFrame();
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
texture.Apply();
}
Your answer
Follow this Question
Related Questions
Can't seem to use GetPixels on a square texture in Unity 3.0 Iphone 0 Answers
Texture2D.ReadPixels not working 0 Answers
Game freezes everything when calling WaitForSeconds 1 Answer
Painting stencil on a surface. 6 Answers
ReadPixels Overlaying Opacity 0 Answers