- Home /
Question by
Krazysh01 · May 22, 2017 at 11:01 AM ·
android buildrendertexture
Render Texture only creating texture of background on android Unity 5.6.0f3
I am attempting to make a screenshot feature that allows the user to take a screenshot and share it to social media. The function works fine in editor however on android it is only creating an image that consists entirely out of the background colour
Here is my current code:
void LateUpdate() {
if (takeHiResShot) {
RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 24);
Camera.main.targetTexture = rt;
Texture2D screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
Camera.main.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
Camera.main.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
/*Texture2D screenShot = new Texture2D(Screen.width, Screen.height);
screenShot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
screenShot.Apply();
byte[] bytes = screenShot.EncodeToPNG();*/
#if UNITY_EDITOR
string filename = Path.Combine(Application.persistentDataPath, "Pixel8_"+System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")+".png");
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("Took screenshot to: {0}", filename));
#else
NativeToolkit.FacebookUploadImage (screenShot, OnScreenShotUploaded);
#endif
takeHiResShot = false;
}
}
This is the output in Editor which is what I expect: But this is the output on android:
I'm not sure whats causing the difference in behaviour between Editor and Build so any help would be greatly appreciated.
Comment
Your answer
Follow this Question
Related Questions
Float texture behaves as Half. Android 0 Answers
Rendering problems on android build 0 Answers
Screenshot only with specified cameras 1 Answer