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 /
  • Help Room /
avatar image
2
Question by Cuicui_Studios · Jun 24, 2016 at 01:31 PM · texture2dwebrequestbytesreadableencodetopng

UnityWebRequest.GetTexture and EncodeToPNG

Hi friends!

I need to ask you about this error with the UnityWebRequest.GetTexture function.

I have a code with the WWW class to get image from Azure, then I create sprites from this images and use them in the game. And before leave the scene, I need to save some of this sprites with EncodeToPng. All my code with the WWW class works. It´s something like this:

 DownloadTexture(){
 WWW www = new WWW (url);
         yield return www;
         Texture2D tex = new Texture2D (1, 1);
         www.LoadImageIntoTexture(tex);
         Sprite image = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0.5f, 0.5f));
 
 someGameObject.sprite = image;
 
 }
 
 SaveSprite()
 {
 byte []bytes = someGameObject.sprite.texture.EncodeToPNG ();
 }
 

I changed some variables and some stuff for simplify the case. With this code works perfect, but it´s a big data manage scene, so I tried UnityWebRequest for better performance. With the new WebRequest the performance is much better so I want to preserve this method, but When I try to save my sprites I have the error "Texture2D is not Readable" And don´t know how to change it. My new code is just a WWW to WebRequest change:

  DownloadTexture(){
 UnityWebRequest www = UnityWebRequest.GetTexture(url);
         yield return www.Send();
     tex = new Texture2D (1, 1);
     tex = ((DownloadHandlerTexture)www.downloadHandler).texture;
          Sprite image = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0.5f, 0.5f));
  
  someGameObject.sprite = image;
  
  }
  
  SaveSprite()
  {
  byte []bytes = someGameObject.sprite.texture.EncodeToPNG ();
  }


Now I get my sprites I can play with them but can´t save them in local.

Does Anyone know how to save this in some other way or make the texture readable or something?

Thanks for your help! Have a good day!

Gabriel

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by wind-tsai · Jul 14, 2016 at 04:40 AM

Unity document say: public static Experimental.Networking.UnityWebRequest GetTexture(string uri, bool nonReadable);

the second parameter say that If true, the texture's raw data will not be accessible to script. This can conserve memory. Default: false.

But, after i tried to set it to be TRUE, i can read the raw data successfully.

Maybe the document make some mistake.

Comment
Add comment · Show 2 · 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 kurtdog · Sep 07, 2016 at 05:13 PM 0
Share

You're awesome! This worked for me, couldn't find the solution anywhere else.

avatar image abertrand · Nov 04, 2016 at 08:07 AM 0
Share

Well spotted, this drove me crazy for hours! Not exactly intuitive that nonReadable should in fact be read as readable ;-)

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

63 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 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

Change Texture2D readable flag at runtime (or at least a workaround to do that) 0 Answers

Unity gives me Not Readable error on texture, but i have it set! 0 Answers

Unity EncodeToPNG saving at 512x512, can't change dimension 0 Answers

Problem to get texture2D in IEnumerator with UnityWebRequest 0 Answers

How to make a script wait for a UnityWebRequest to finish for WebGL without a coroutine? 1 Answer


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