- Home /
SetTexture Not Working
After upgrading from Unity 5.1.1f1 to 5.3.1f1, I have a feature in my game using SetTexture/ RenderTexture which no longer works. I have a build of the game running on a separate laptop using 5.1.1f1 which still works correctly. The code looks like this:
m_ScreenShot = CaptureScreen();
m_ScreenCapMat.SetTexture( 0, (Texture)m_ScreenShot);
The CaptureScreen function consists of this:
RenderTexture CaptureScreen() {
Camera screen_cap = m_ScreenShotCam.GetComponent<Camera>();
screen_cap.enabled = true;
RenderTexture rt = new RenderTexture( screen_cap.pixelWidth, screen_cap.pixelHeight, 24 /*depth*/);
screen_cap.targetTexture = rt;
screen_cap.Render();
screen_cap.enabled = false;
return rt;
}
Do I need to update something to get this working in 5.3.1f1?
No, there's no error message - it just fails to replace the current texture with what it should have captured.
http://docs.unity3d.com/ScriptReference/Camera.Render.html
Check out this example. $$anonymous$$aybe that helps you further.
Answer by NiKoMaKi · May 30, 2016 at 01:20 PM
@Esperento I just came across this same problem. What fixed it for me was referring to the texture by id and not index. So instead of SetTexture(0, MyTexture) try SetTexture("_MainTex", MyTexture). Or depending on your shader, the main texture could be named something else. At any rate, setting a texture by index doesn't seem to work any more. The function is still there, though, so I wonder if this is a bug.
Yes I ran into the same issue. I was working with Unity 5.2.1 using SetTexture(0, $$anonymous$$yTexture) and when using the same code in Unity 5.3.x it didn't work. This change fixed the issue. Thanks @Niko$$anonymous$$aki :)
Your answer
Follow this Question
Related Questions
Output texture has a material problem 0 Answers
Set Texture on only particular part (portion) of a Sphere 1 Answer
grab textures from texturesheet 0 Answers
Unity 4.6 project upgrade 0 Answers
Abnormal Mesh Bounds after upgrading to Unity 2017.4.33 0 Answers