Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
3
Question by nyonge · Jun 17, 2015 at 07:15 AM · texture2druntimetextureimporterreadable

Create / Modify Texture2D to Read/Write Enabled at Runtime

How can I create or edit a texture, at runtime, with its read/write property enabled? The TextureFormat doesn't seem to help, and I can't find out how to make it work.

Note: TextureImporter and AssetDatabase don't work. They require the UnityEditor namespace, and that doesn't work in an exported build (I'm making this for iOS).

In the editor, you can just set a texture's type to Advanced and set its Read/Write Enabled property to true, but of course I don't have access to the editor at runtime.

Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by kamyflex · Mar 17, 2020 at 03:57 AM

From here : https://stackoverflow.com/questions/44733841/how-to-make-texture2d-readable-via-script @nyonge , i got this, and it worked well for me :

 Texture2D duplicateTexture(Texture2D source)
 {
     RenderTexture renderTex = RenderTexture.GetTemporary(
                 source.width,
                 source.height,
                 0,
                 RenderTextureFormat.Default,
                 RenderTextureReadWrite.Linear);
 
     Graphics.Blit(source, renderTex);
     RenderTexture previous = RenderTexture.active;
     RenderTexture.active = renderTex;
     Texture2D readableText = new Texture2D(source.width, source.height);
     readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
     readableText.Apply();
     RenderTexture.active = previous;
     RenderTexture.ReleaseTemporary(renderTex);
     return readableText;
 }
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 shacharoz · Aug 21, 2020 at 05:05 PM 0
Share

this code saved my ASS :) well done!

avatar image rmib200 · Dec 25, 2021 at 08:43 PM 0
Share

My texture is blank when I use this method. Do you how to fix that?

avatar image
2

Answer by Bunny83 · Feb 21, 2017 at 08:57 PM

"Readonly" only applies to assets that you import at edittime. So if you imported a texture at edittime and you didn't make it readable, you can't read it at runtime and you can't make it readable. So if you need textures which you imported in the editor readable at runtime you have to mark it as readable inside the editor.

Textures created at runtime are always readable unless you pass "true" as second parameter to Apply in which case you made the texture none-readable forever just like an asset that never was.

If you load images at runtime from external sources they also are readable by default

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

Answer by MikeHergaarden · Feb 21, 2017 at 08:17 PM

If you want to make something readable, you'd best create a new readable texture at runtime.

If you want to make a read/write texture "static", use: https://docs.unity3d.com/ScriptReference/Texture2D.Apply.html

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

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

26 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

Related Questions

Reading pixels from texture2D (how to make texture readable?) 2 Answers

Can not retrive image form device to the plane at runtime. 0 Answers

Can't Resources.load new generated texture2D as lightmaps at run time 0 Answers

Using Texture2D created at runtime to create a Sprite decreases Sprite quality. (Android) 1 Answer

Stop compressing image on Android 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