Hi there,
I’m trying to find memory bottlenecks in our game but I’m having a tough time figuring out what to tackle.
- Our biggest usage area, Assets, takes up 0.9 GB, yet the total allocated is 1.3 GB. Where is this extra bulk coming from?
- What is AssetDatabase? It is the biggest consumer under Assets. If it is editor-only, as said in the documentation, should I be concerned with it?
- This is the second time I’m asking this - How does unity manage memory taken by assets (like textures) that will not be used for long periods of time? Our game is procedural, and as a consequence it is possible for any given mesh, texture, audio clip, etc. to be used at any given time. But obviously it is not a viable option to dump every single thing into RAM upon loading the level.
For example, Unity loads a texture for every single weapon, item, character, enemy, etc. even if the player will not encounter said objects even after hours of gameplay. For example, the player might require 10,000 metal to build a super death missile, but the player won’t necessarily have those resources for a long time. Yet since the possibility of them being built is there they are ALL loaded onto memory, all at once. Is there any way to get around this? Where instead I load it into memory when I KNOW it will be used, and discard it when I KNOW it won’t be?
Perhaps more importantly - Shouldn’t Unity be doing this for me? Surely it is the role of the engine to know what textures, meshes, audio clips, animations, etc. are being rendered, displayed, played, etc. at any given time. Surely it is the role of the engine to know the reference count for a given asset and to purge it from memory when it is not being referenced anymore. Surely it is the role of the engine to track when GameObjects use or stop using a particular asset, so that the reference count of a given asset can be known. Yet consistently it seems that assets that are not being used at the time are wasting space as if none of this was happening. Please tell me that I am doing something wrong, at that there is actually a simple solution for this.
Thanks to anyone who might be able to help.