RenderTexture.active not working on iOS

Hey Guys,

I am trying to take a screenshot using a render texture. My code works fine in the editor and on Android too, but on iOS, I get a white texture. I am surprise because, when a texture is empty, I though that it was all black, so it seems like it captures something, but it is all white. Here is my code :

public IEnumerator TakeScreenShot()
	{
		yield return new WaitForEndOfFrame();
            mTex = new RenderTexture(Screen.width, Screen.height, 0);
		RenderTexture tempTexture = RenderTexture.active;
		RenderTexture.active = mTex;
		Camera.allCameras [0].targetTexture = mTex;
		RenderTexture.active = tempTexture;
		Camera.allCameras [0].targetTexture = null;

		gameObject.GetComponent<MeshRenderer> ().materials [0].SetTexture (0, mTex);
		gameObject.GetComponent<MeshRenderer> ().materials [1].SetTexture (0, mTex);

		StartAnimation ();
	}

Does anybody have an idea ? Thanks a lot for your time !

Claude

1 Answer

1

Found it, the problem was not the RenderTexture.active, it was actually the part where I do my SetTexture, I replaced it with : SetTexture(“_MainTex”, mTex); and it works like a charm. Thanks a lot !