- Home /
Prevent Resources class from loading assets when application starts
Hi! My application has a lot assets in Resources folder, but I use only some part of them at one time. Before first scene is loaded, my app takes over 700MB of memory... In Start method in my MonoBehaviour class I use Resources.UnloadUnusedAssets()
and it frees over 600MB :) After that everything works just fine.
Is there any way to prevent UnityPlayer from loading all assets into memory when application starts?
Answer by Lovrenc · Oct 04, 2013 at 01:15 PM
Resources is special folder in unity (List of special folders). Unity always loads all assets from resources folder. You can move assets to different folder. Then unity will determine what he needs and will only load those assets.
Use Resources folder for assets that are not by default in your scene, but there might be a case in which you want to put it in the scene. Unity will load them and you can access them via Resources.Load.
Thanks for answer! The problem is that my app has to work on Windows PC, Android and iOS... There is only one scene and it loads and unloads assets dynamically based on xml files... Resources class is the only way to manage all assets on many platforms... I don't understand why by default every asset from Resources folder has to be loaded into memory when app starts... especially when everything works when I use Resources.UnloadUnusedAssets()
O$$anonymous$$, have some new informations... Before, I used Resources.LoadAll("Path/", typeof(TextAsset));
to load my xml files containing informations about my scenes... After calling this function usage of memory grown to almost 1GB :/ Now I load each xml file separately using Resources.Load("Path/", typeof(TextAsset));
and problem is solved... but only on Windows... Under Android it still loads whole resources into memory when application starts :/ Please, help me... (going insane)