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 benfattino · Sep 19, 2013 at 09:57 PM · unloadunloadunusedassets

UnloadUnusedAssets

I have a script that load a 2048px texture from a Resources folder follow an index (FrameINT):

 #pragma strict
 var OBJ : GameObject;
 var TextName : String = "";
 var FrameINT : int ;
 var FrameOLD : int;
 var Tempo : float = 0.0;
 var velocity : float = 0.05;
 
 function Awake () {
 OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString()+ "_" + Manager.Frames.ToString(), Texture));
 }
 
 function Start () {
 }
 
 function Update () {
 FrameOLD = FrameINT;
 FrameINT = Manager.Frames;
  
 if ( !Manager.FadeON && FrameOLD  != FrameINT){
 OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString()+ "_" + FrameINT.ToString(), Texture));
 }
 
 if (Manager.FadeON){
 AssignTexture();
 }
 }

 function AssignTexture () {
 OBJ.renderer.material.SetTexture("_MainTexture2", Resources.Load(TextName + Manager.SceneNumber.ToString() + "_" + FrameINT.ToString(), Texture));
 
     if (Tempo < 1.0){
     Tempo = Tempo + velocity;
     OBJ.renderer.material.SetFloat("_Blend", Tempo);
     }
     else if (Tempo >= 1.0){
     OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString() + "_" +         FrameINT.ToString(), Texture));
     
     Tempo = 0.0;
     OBJ.renderer.material.SetFloat("_Blend", Tempo);
     Resources.UnloadUnusedAssets();
 
     Manager.FadeON = false;
     Manager.TouchON = true;
 
 }
 }

This system work great and give me possibility to load a large number of big size texture. At first, the application works fine, but with each new load gets too slow. I try to use :

   Resources.UnloadUnusedAssets();

to unload unused assets but seem not to work. There is a right way to unload unused texture and speed up my application?

Comment
Add comment · Show 3
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 Tarlius · Sep 20, 2013 at 09:17 AM 0
Share

I have to ask why you are loading such a large texture for what seems to be an animation...? Are you sure you couldn't fake it another way?

avatar image benfattino · Sep 20, 2013 at 10:11 AM 0
Share

I have a system like 360° viewer where there is a sequence of image that I control with swipe gesture. I'm a newbie programmer and seem the best solution...

avatar image Tarlius · Sep 25, 2013 at 02:32 AM 0
Share

Sorry for late reply. I thought maybe you were doing a fullscreen animation with it or something. You might be able to increase the throughput by using lower resolution "previews" while moving then swapping for a higher-resolution version when the camera "slows", or breaking them down into smaller images. Although it all depends on your (desired) implementation.

If you are using the free version of Unity, I think you will have to block either way though, since asynchronous loading/asset bundles is a pro feature.

Note that if a file is already loaded, Resources.Load should not take very long at all since the load is skipped and its just a lookup.

Note that depending on your target hardware/the total size of the view, it might be feasible to cache all the images while showing a loading screen.

1 Reply

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

Answer by Sisso · Sep 20, 2013 at 01:22 AM

The UnloadUnusedAssets and UnloadAsset is the right way to unload assets. For it work, you have to be sure that there is no references.

You said that it become slow. I don't think that could be the use of memory, use of memory don't make a game slow until you fill it and the SO start to paginate.

In your code there is many Resource.Load, and even inside a Update function. With "big size texture" it could really get things slow. The Resouces.Load is a very slow operation, and wich I know, there is no cache optimization from unity3d.

Try to profiling deep and see what is really slowing down. This could help:

http://wiki.unity3d.com/index.php?title=Profiler

Comment
Add comment · Show 4 · 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 benfattino · Sep 20, 2013 at 08:51 AM 0
Share

Thanks for answer. I now that LoadResource is slow but for my project is perfect because i have a lot of highres texture. I am a newbie and would like to understand what you mean by references. $$anonymous$$y script is attached to plane and texture load every time i need. This mean I must delete the plane before unload resource? To conclude I think that the problems are elsewhere...

avatar image Sisso · Sep 20, 2013 at 12:43 PM 0
Share

Reference is everything that point to your assets. If your plane is using a texture, it is a reference. For example, before clean up a texture a could remove the reference from my plane:

plane.GetComponent($$anonymous$$eshRenderer).shared$$anonymous$$aterials = []; Resources.UnloadUnusedAssets();

In your case you replace the texture before unloadall, so, the old texture should be cleanup.

Resources.UnloadUnusedAssets is also very slow. If you call each frame, you could expect slow downs.

You really need to profiling your code to know how many times and how much time the Resorces.Load and UnloadAssets are taking each frame.

Unity3d pro has some tools, you could give a try in 30 days trial.

avatar image nanditho · Jun 18, 2019 at 10:34 AM 0
Share

What is the tools that unity Pro has to solve the problem? Thnaks @Sisso

avatar image Sisso nanditho · Jun 19, 2019 at 06:10 AM 0
Share

@nanditho

That was in 2013, I was talking about the Profiler that was only available in Unity Pro.

https://docs.unity3d.com/$$anonymous$$anual/Prof1iler.html

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

18 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

Related Questions

Static mesh smooth, safe Unload ? 2018.1 2 Answers

why UnloadUnusedAssets doesn't unload a asset? 0 Answers

Does Unloadunusedassets unload unused assets loaded from Assetbundles? 0 Answers

[AssetBundles] - Why is my assetbundle.unload not unloading assets and therefore cannot loadfromcacheordownload again ? 0 Answers

Issues with unloading textures and atlases 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