- Home /
Prefab with UI.Text is not unloaded
I'm doing optimization test to reduce memory usage.
When I destory all prefab-instances, there is a case that prefab is not unloaded as if there are undestroyed prefab-instances.
I realize a prefab couldn't be unloaded when a prefab-instance has references for other assets using public field.
So, I removed references by setting them null in OnDestroy() event.
It seemed to work very well. But I realized there is another case making prefab cannot be unloaded.
If there is a GameObject with a UI.Text component, that prefab will be never unloaded.
How could I fix this problem?
I have the same issue, tried moving the font of the UI.Text to resources to see if it was an issue with Resources.Load but the problem remains. Hope someone can fix this.
I'm a little confused about what you mean. You say "with UI.Text the prefab will never be unloaded". The screenshot shows "With Text, Texture2Ds are unloaded", but are visible within the memory sample.
Can you explain again what exactly the problem is?
Sorry, my issue isn't related to the screenshot (but similar). $$anonymous$$y issue is a prefab with UI.Text, when loaded thru Resources.Load() will NOT unload properly. The prefab will show in the memory profiler even after Resources.UnloadUnusedAssets() is called.
Still trying to figure out the cause, Im suspecting the font (in Assets/Fonts) used by my prefab(in Resources) triggered something in Unity to keep a static reference of the prefab.
Answer by lifeisforu · Sep 22, 2017 at 09:30 AM
My mistake. It means if you delete prefab instance with text, it's texture will never be unloaded. I guess the situation occurs because of text atlas for the text.