- Home /
OutOfMemoryException: Out of memory
Im getting this weird error whenever I run my game, a google search reveals nothing specific to unity. Does anyone know what this runtime error is or how to fix it?
EDIT im now getting it every update and when i compile my script, how do i get rid of this? there is almost no textures on the screen and i am getting ~300 fps! Thanks!
Answer by MileSplit · Feb 28, 2014 at 03:35 AM
My problem ended up that i had too large of an array, it was
public Vector3[,,,] tooLargeOfAnArray = new Vector3[50,50,1000,1000];
Because of this, the compiler could not initialize it all so it told me it ran out of memory, then every time i referenced tooLargeOfAnArray it ran out of memory and told me.
Answer by Anxo · Feb 27, 2014 at 11:17 PM
If you are using a lot of textures this may happen. It might not have much to do with your actually ram but more with the limited ram it is allowed to use. In an effort to avoid this, You can dump your textures in a resources folder and load them as needed instead of having them in the scene. That allows you to dump them from memory when they are no longer in use which becomes much more memory efficient.
Resource.Load https://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html
Resource.UnloadAsset https://docs.unity3d.com/Documentation/ScriptReference/Resources.UnloadAsset.html
Answer by ChrisSch · Feb 27, 2014 at 11:20 PM
OutOfMemoryException error means you've ran out of your free RAM memory, and the game usually crashes. So if you have 2gb of free memory it happens when it fills up those 2gb and the game crashes cause it needs more. Like my modded Skyrim and Minecraft. xD
Does it happen in every scene (new scene) or just on the current one you're working with? Assuming its the latter, and not Unity's fault, then you have something seriously filling up your free memory. That's all I can tell you with that much info.
Ah, yes that could be it. I'm also working on a procedural dungeon generation and have had bugs where it generates to infinity, but never had that error, it just froze up Unity after a good number of torch/chest filled dungeon rooms. xD
Probably cause I never built and ran it while it was bugged.
I just noticed this and i was wondering if somone could help, i get this error when i play AND once my code finishes compiling, but it doesn't stop me from playing...