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
0
Question by kromenak · Apr 23, 2014 at 07:28 PM · androidiostexturememoryresources.load

Can I load textures at runtime with a smaller memory footprint?

I've got some PNG byte data in my Resources folder that I want to load at runtime on Android and iOS devices. The image file itself is 2048x4096, which equates to an uncompressed RGBA 32-bit image at 32MB, according to the Texture Import Settings.

So, I take my 32MB texture, give it a .bytes extension, and throw it into the Resources folder. Then, at runtime on an Android device, I call this code to load the bytes into a texture:

 TextAsset imageBytes = Resources.Load( atlasPath, typeof( TextAsset ) ) as TextAsset;
 texture = new Texture2D( 0, 0, TextureFormat.ARGB32, false );
 texture.LoadImage( imageBytes.bytes );
 texture.name = atlasPath;
 
 Resources.UnloadAsset( imageBytes );

This works well, but we come to my question: is this the best way to load a texture dynamically at runtime to achieve the best performance/memory usage?

Specifically, I've noticed that when I profile memory usage at runtime, my originally 32MB texture is now 64MB in memory! For some reason, the texture size has doubled. Is this a side effect of using the "LoadImage" function? Or does it have something to do with the image being "Read/Write Enabled"? Is there anyway to avoid that sort of memory bloat when loading a texture dynamically like this?

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 kromenak · Apr 23, 2014 at 07:59 PM 0
Share

Hmmm...I'm inheriting some code that was using the program "TexturePacker" to generate byte data as part of their asset pipeline. However, I'll try loading Texture2D directly and see if the result is any different. Thanks for the tip!

avatar image kromenak · Apr 23, 2014 at 08:53 PM 0
Share

Ah, big win! I changed it to directly load Texture2D and the texture is back to 32$$anonymous$$B in memory. I suspect that using LoadImage may cause the loaded texture to have Read/Write enabled, which I read somewhere will double the in-memory size of the texture. Loading the Texture2D directly doesn't have that problem.

Thanks again!

avatar image xortrox · Apr 23, 2014 at 09:23 PM 0
Share

It was most likely due to the fact you assigned the bytes to "TextAssets" and then created a new texture out of those bytes (making new texture 32$$anonymous$$B as well as the bytes in TextAsset being 32$$anonymous$$B)

avatar image kromenak · Apr 23, 2014 at 11:40 PM 0
Share

That would make sense, but I'm only seeing one resource at 64$$anonymous$$B, not two separate resources as 32$$anonymous$$B each. In any case, it's an improvement for sure.

1 Reply

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

Answer by xortrox · Apr 23, 2014 at 07:47 PM

How come you don't load the texture as typeof(Texture2D) instead? Texture2D myImage = (Texture2D)Resources.Load("images/somepicture.png");

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

21 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

Related Questions

garbage collection not cleaning up material that isn't referenced on android 1 Answer

Is it possible to copy texture "Override for ios" to android? 1 Answer

Unity 5 Resources.LoadAsync on Android slower than iOS? 0 Answers

ridiculous load time using Resources.Load() on android build 0 Answers

Changing textures accumulate in memory. iOS. 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