Fast Converting RenderTexture to Texture2D
I have a screenshot preview at the end of the game's level. When I am loading the screenshot, it makes game freeze for a moment. What shall I do, so there would be no freeze, when I am loading that screenshot? Here is mycode:
private IEnumerator ShowScreeshotPreview()
{
screenshotTexture = new Texture2D(Screen.height, Screen.height, TextureFormat.RGB24, false);
for (int i = 0; i < 9; i++)
{
yield return null;
}
RenderTexture.active = Singletons.Get<SpecialEffectsHelper>().MainCharacterScript.GetComponent<GeneratorScript>().screenshotTexture;
screenshotTexture.ReadPixels(new Rect(0, 0, Screen.height, Screen.height), 0, 0);
screenshotTexture.Apply();
RenderTexture.active = null; //Added to avoid errors
screenshotPrview.mainTexture = screenshotTexture;
ScreenshotPreviewAnimator.SetBool("visible", true);
screenshotLoaded = true;
yield return null;
}
I know this is an old comment, and you have probably already fixed it, but getting components, gameobjects, and scripts are costly operations, so part of your problem might be in the chain of getting components on line 8.
Answer by XinYueVR · Aug 28, 2017 at 02:22 AM
“screenshotTexture.ReadPixels(new Rect(0, 0, Screen.height, Screen.height), 0, 0); screenshotTexture.Apply();”
it is not fast, It takes a lot of time and Influence performance Is there a new way to solve the problem?
Your answer
Follow this Question
Related Questions
how can i store a screenshot into android mobile? 0 Answers
ScreenCapture.CaptureScreenshotAsTexture() is making a milky white tinted screenshot. 1 Answer
Capturing high resolution screenshot with Temporal AA 1 Answer
how simply writing text on texture 0 Answers
Black screen capturing screenshot 0 Answers