Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by FreeTimeDev · Nov 01, 2014 at 05:38 PM · texturetexture2druntimealpha

Difficulty loading alpha textures at runtime

I'm using the following excerpt to load an image from a file at run time:

 if(detail != customOld)
             {
                 print ("It is a custom detail to build");
                 Texture2D tex = new Texture2D(1,1, TextureFormat.ARGB32, false);
                 byte[] bytes = System.IO.File.ReadAllBytes(dir+detail+".png");
                 print (dir+detail+".png");
 
                 tex.LoadImage(bytes);
                 tex.wrapMode = TextureWrapMode.Clamp;
                 tex.Compress (true);
 
                 customDetail.GetComponent<SpriteRenderer>().sprite = Sprite.Create(tex, new Rect(0f,0f,128f,128f),new Vector2(.5f,.5f),256f);
                 customDetail.name = detail;
 
                 customDetail.GetComponent<Detail>().detailName = detail;
                 customOld = detail;
 
                 
 
                 
                 
             }
             detailToBuild = customDetail;

It works, except seemingly when the pictures have alpha. After I changed the texture being loaded to one that was solid the texture loaded as expected. After I changed the original texture to have no transparency the result was a white square. However, the texture that did load correctly shows all of the detail.

What gives?

Edit:

alt text White background -- shows White square.

alt text Transparent background -- shows nothing.

wellwhite.png (9.3 kB)
welltrans.png (10.7 kB)
Comment
Add comment · Show 2
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 Nebukam · Nov 02, 2014 at 05:10 AM 0
Share

Try using WWW.LoadImageIntoTexture to load your texture (use DXT5 ins$$anonymous$$d of DXT1 from the the provided example) ins$$anonymous$$d of System.IO, and see if it solves your issue.

avatar image FreeTimeDev · Nov 02, 2014 at 06:56 PM 0
Share
 tex = new Texture2D(128,128, TextureFormat.DXT5, false);
         var www = new WWW(dir+"/"+myTile+".png");
         yield return www;
         www.LoadImageIntoTexture(tex);

Had the same results. I've also tried doing what's below because I thought maybe mipmaps had something to do with it.

 Texture2D tex = new Texture2D(128,128, TextureFormat.DXT5, false);                                byte[] img = System.IO.File.ReadAllBytes(dir+"/"+myTile+".png");                                Debug.Log(dir+"/"+myTile+".png");                                tex.LoadImage(img);                                tex.ReadPixels(new Rect(0,0,tex.width,tex.height), 0,0);                                tex.wrap$$anonymous$$ode = TextureWrap$$anonymous$$ode.Clamp;                                tex.Compress (true);
                                 tex.Apply();

0 Replies

· Add your reply
  • Sort: 

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

27 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

Related Questions

Blending two Texture2D 1 Answer

Determine if a Texture2D has alpha 3 Answers

Texture2D: pixel Specific alpha not working? 4 Answers

Changing color of texture with transparency efficiently 0 Answers

Make a Texture2D gradient during run-time 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