- Home /
Long load time for scene... Some optimization questions.
I apologize if this has been answered before but I could not find a satisfactory answer to this question.
I have a scene that has many different activities that are similar in nature but have separate resources. They are not similar enough to use the same code but not different enough to be in separate scenes. I created several empty GameObjects to act as a container for each "mini-scene". I call, for example, PartOne.SetActive(true) when I want it to be visible and set it to false when I want it to turn off.
Looking back, perhaps creating several different scenes and calling LoadLevelAdditive (asynchronously or not) may have been better but I really don't have time to refactor right now.
There are a couple of questions that I can't find the answers to in the Unity documentation (or anywhere for that matter) that could help me out. Of course, any other ideas are also welcome.
If I create a public variable and drag a texture (for example) to it in the inspector, is that texture loaded into memory when the scene is loaded or does it cache it somehow?
If I create said public variable and it is the child of another GameObject, is the parent (as well as the other items in that hierarchy) loaded into memory?
If a child GameObject is active but it's parent is not, are the children loaded into memory?
Is using Resources.Load too slow to load high-res images?
Is there any way to cache images in a temp directory or any other magical feature that I am missing?
Thanks! Any other feedback or ideas would be appreciated!
Answer by Jessespike · Nov 12, 2013 at 03:01 AM
I answered these questions the best I could. I may be wrong, if that's the case then I hope someone will correct me.
1) When the scene starts, the texture will have been loaded into memory. If you have two public variables referencing the same texture, more memory is used. Even though they're the same texture, each reference will take up memory. There is no texture sharing or caching.
2) Yes, the entire hierarchy will be loaded into memory, even if it's inactive.
3) Yes
4) Depends on you're definition of "too slow". Also depends on what hardware you're targeting. I would imagine, loading multiple high-res images would cause a stutter at least, maybe even freeze for a couple of seconds on slower machines.
5) Perhaps you could pool your textures with a "TextureCache" or manager. Have a singleton class DontDestroyOnLoad and have a public list of materials, so you can store a single reference of each texture. Then, when you need a specific texture/material you can grab it from here. (Don't know if this applies to you're project, just throwing ideas.)
I'm guessing you already compressed the textures to a compatible format and making use of sharedMaterials. But if you haven't then that would a be a good idea. Other things that may improve texture load times would be removing mipmaps (when not needed). Reducing texture sizes. Make sure texture resolution is a power of 2. Disabling read/write. Use masks for transparency instead of alpha. If you have two or more identical textures but they vary in color, then use one grayscale version and use a shader to color them. Use atlases for GUI and sprites. Combine smaller textures.
http://docs.unity3d.com/Documentation/Manual/iphone-PracticalScriptingOptimizations.html#Object%20Pooling http://docs.unity3d.com/Documentation/Manual/Textures.html
Thank you so much! I suspected many of these things but it is good to have them confirmed.
We have done most of the things that you suggested above but a few that we haven't. Thanks again!
Your answer
Follow this Question
Related Questions
How to have 2 sets of textures and make sure only one is loaded? 0 Answers
Prevent Resources class from loading assets when application starts 1 Answer
How to determine which resources are loaded while loading scene 1 Answer
AssetBundles, memory, and loading 0 Answers
Do I need to manually call Resources.UnloadUnusedAssets? 0 Answers