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
2
Question by pekalicious · May 09, 2013 at 05:28 PM · optimizationtexture2dmemory

Are Texture2Ds in a Resources folder always loaded in memory?

Hey Unity people,

I used this small script to print out all loaded Texture2D in my game and I noticed that some of them are loaded even if I'm 90% sure they shouldn't be. Here is the script:

 var textures = Resources.FindObjectsOfTypeAll(typeof(Texture2D));
 int totalBytes = 0;
 foreach (Texture2D t in textures)
 {
     int memorySize = Profiler.GetRuntimeMemorySize(t);
     if (memorySize > 0.4f)
         Debug.Log("Texture object " + t.name + "(" + t.width + "x" + t.height + "|" + t.format + ") using: " + memorySize + "Bytes", t);
     totalBytes += memorySize;
 }
 Debug.Log("Total bytes: " + totalBytes);

I tried Resources.UnloadUnusedAssets to unload those assets but that doesn't seem to make any difference.

My main question is: do Texture2Ds automatically load into memory when they are placed in a Resources folder whether you use them or not?

Side questions: How can I tell why is that Texture loaded in memory? Is somebody referencing it? How can I search the scene for the game object that references it?

Thanks in advance.

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
Best Answer

Answer by whydoidoit · May 09, 2013 at 06:12 PM

No textures in Resources are not always loaded into memory (they are always included in the build). However as they are always accessible to a Resources.FindObjectsOfTypeAll then they will be loaded into memory when that code runs.

You can tell what uses something in the editor by running a scene, finding the texture in the project, right clicking and use Find Scene References.

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 pekalicious · May 09, 2013 at 06:23 PM 0
Share

Erm..... So basically, by just running that code, I load all textures in memory? Haha! That's good to know. I did run the Find Scene References but wasn't finding anything referencing what my code was saying. But I guess now it makes sense why. Thanks!

avatar image whydoidoit · May 09, 2013 at 08:14 PM 0
Share

Yep that's what happened :)

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

14 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

Related Questions

Texture and Texture2D for GUI (simple question) 1 Answer

Texture Doubled in size in RAM Profiler 3 Answers

Releasing assets loaded from asset bundle 1 Answer

Quality level and cubemaps 1 Answer

UI-based game memory and performance issue. 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