Unity3d Huge memory usage textures

1

I have a 3D endless runner game built in Unity3D running on iOS, Android and Windows Phone.

It works fine on Windows Phones with 1014MB memory and above, but under that it crashes as soon as it starts (see error message from Visual Studio at the bottom of this post).

Looking at the profiler I can see the memory usage for textures is extremely high, knowing that I only get a maximum of 180MB RAM on a Lumia 520 for example, I can see from the profiler that the textures take up 359MB alone, and even at eighth res (screenshot below) they still take up 232MB! I have gone through every texture making it as small and compressed as I can, am I doing something really wrong here? How can I find out more about what textures are problems?

I usually preload all the procedural level elements into memory at the start of the game to help the frame rate once you're running, but even when I turn this off completely the memory usage is unaffected.

Any pushes in the right direction would really help, thanks!

memory usage

Visual Studio crash console log dump:

'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: DefaultDomain): Loaded 'C:\windows\system32\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Windows.RuntimeHost.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Windows.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Net.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Xml.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\EndlessRunner.DLL'. Symbols loaded.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\Microsoft.Phone.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\Microsoft.Phone.Interop.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\WinRTBridge.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\BridgeInterface.winmd'. Module was built without symbols.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\UnityPlayer.winmd'. Module was built without symbols.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\WinMetadata\Windows.winmd'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Core.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Runtime.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Build from 'release/4.5/release' branch, version is '4.5.0f6 (fd4616464986)' (Release build).

Physical memory: 395 MB, commited memory limit: 180 MB.

PlayerConnection initialized from C:/Data/Programs/{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}/Install/Data (debug = 0)

PlayerConnection initialized network socket : 0.0.0.0 55444

Multi-casting "[IP] 192.168.0.19 [Port] 55444 [Flags] 2 [Guid] 93005236 [EditorId] 1016877170 [Version] 1048832 [Id] WP8Player(192.168.0.19) [Debug] 0" to [225.0.0.222:54997]...

Direct3D:

    Version:  Direct3D 11.0 [level 9.3]

    Renderer: Qualcomm Adreno 305 (WDDM v1.2) (ID=0x30303330)

    Vendor:   Qualcomm

    VRAM:     96 MB

Initialize engine version: 4.5.0f6 (fd4616464986)

'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\UnityEngine.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\Assembly-CSharp-firstpass.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\Assembly-CSharp.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\BFSWP8Goodies.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\GPGSUtils.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\Data\Programs\{DFE540D3-80C1-4CFF-BFCA-CE252BC4EECE}\Install\WinRTLegacy.DLL'. Module was built without symbols.
Could not allocate memory: System out of memory!
Trying to allocate: 1398128B with 32 alignment. MemoryLabel: Texture
Allocation happend at: Line:411 in C:/BuildAgent/work/aeedb04a1292f85a/Runtime/Graphics/Texture2D.cpp
Memory overview


[ ALLOC_DEFAULT ] used: 5715133B | peak: 5715181B | reserved: 6570457B 

[ ALLOC_GAMEOBJECT ] used: 43508B | peak: 43508B | reserved: 52731B 

[ ALLOC_GFX ] used: 155628390B | peak: 155628390B | reserved: 155631656B 

[ ALLOC_PROFILER ] used: 5028B | peak: 5028B | reserved: 12158B 

Could not allocate memory: System out of memory!
Trying to allocate: 1398128B with 32 alignment. MemoryLabel: Texture
Allocation happend at: Line:411 in C:/BuildAgent/work/aeedb04a1292f85a/Runtime/Graphics/Texture2D.cpp
Memory overview


[ ALLOC_DEFAULT ] used: 5715133B | peak: 5715181B | reserved: 6570457B 

[ ALLOC_GAMEOBJECT ] used: 43508B | peak: 43508B | reserved: 52731B 

[ ALLOC_GFX ] used: 155628390B | peak: 155628390B | reserved: 155631656B 

[ ALLOC_PROFILER ] used: 5028B | peak: 5028B | reserved: 12158B 


(Filename: C:/BuildAgent/work/aeedb04a1292f85a/Runtime/Allocator/MemoryManager.cpp Line: 909)


The program '[2540] TaskHost.exe' has exited with code -2147483645 (0x80000003).
memory
windows-phone-8
unity3d
textures
asked on Stack Overflow Sep 24, 2014 by bbeckford

2 Answers

0

I have gone through every texture making it as small and compressed as I can, am I doing something really wrong here? How can I find out more about what textures are problems?

Hum.. I don't think you are doing something wrong. Memory limitations on hardware are hardware issues not artist issues. However, artist have to cope with restrictions in order to be able to cope with hardware limitations, then:

  1. If you do 3D you can: make sure your models has as less materials as possible. The more materials you have on a model the more individual textures will most likely be required for such model. If you still need to, then make sure other models can share the same materials if possible or share some mesh groups so you can optimize on draw calls a tad.

  2. If you can the usage of an Atlas texture is also good help, as its considered only one material. Then it will not help you that much with memory since it will still takes the same memory. It will only helps against draw calls mostly.

  3. Like LearnCocos2D says, bits per color is a huge *if even if the textures are 'small' try not using 32 bit textures for example.

  4. Texture resolution or texels are key. If you are using a character and your character is small at the mobile screen, then you should be good with really small textures. For example, in certain games the character is say 6' in height and an 8' foot wall is translated into a 512x512px texture in terms of coverage for say a brick's patch in a wall section that can look fairly good in contrast with the character. So for example going higher in such 8' foot equivalent height wall in contrast with such character will already be starting to waste resources and the visual impact will be minimum or not noticeable at all. It is important to define texel resolution for a 3D mobile game in order to be able to better plan your texturing resources.

    I recommend you this tutorial if you can, its really informative about this issues: http://www.digitaltutors.com/tutorial/1772-Creating-Professional-Studio-Game-Assets-for-Production-in-3ds-Max-and-Unity

  5. Then lastly in your case since its an infinite you really need to use enable/disable instead of destroy and also make sure the distance of the camera culling is exactly what you needed it be, otherwise you'll load lots of player unseen objects without need, this could be a boomer too... just saying.

answered on Stack Overflow Sep 27, 2014 by CodeAssembler • edited Sep 28, 2014 by Pang
0

I do see memory usage issues often in projects made with Unity. Once you have gone through the typical optimizations such as texture compression settings, you can try another approach. Since recently, Unity published a package called Addressables. This will allow you to keep references to your assets without them being loaded. There, it is up to you when to load/unload them. I wrote a detailed blog post about them, it might help you. Find it in https://thegamedev.guru/unity-addressables-learn-workflows/

answered on Stack Overflow Sep 11, 2019 by (unknown user)

User contributions licensed under CC BY-SA 3.0