Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Esperento · Jan 25, 2016 at 03:59 PM · unity 5texturerendertextureupgradeset

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?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image antx · Jan 25, 2016 at 04:04 PM 0
Share

Do you get an error message? If so, can you post it here?

avatar image Esperento antx · Jan 25, 2016 at 04:23 PM 0
Share

No, there's no error message - it just fails to replace the current texture with what it should have captured.

avatar image antx Esperento · Jan 25, 2016 at 05:46 PM 0
Share

http://docs.unity3d.com/ScriptReference/Camera.Render.html

Check out this example. $$anonymous$$aybe that helps you further.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chusmaverde · Sep 19, 2016 at 01:52 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges