- Home /
Running out of memory when loading scene (worked perfectly until about an hour ago - no change to scene).
So, I've been getting a rather infuriating error where Unity has started running out of memory when loading my scene. The interesting thing is that this has only just started happening, and the scene being loaded has not changed.
The only difference between this build and a working one is the presence of music playing on the scene previously, which is streaming from the disc and should not significantly alter the memory footprint. The memory usage of the level once loaded is a little over 1GB, but seems to be more than double this while loading (the scene I am loading from is quite light weight). What I also find interesting is that all of the peak values on the error report are 0B, which seems very odd. It also seems odd that none of the "used" values are above the "allocated" ones, which should mean I have some memory left to use. I'm also not running out of memory overall, as my memory usage isn't reaching 100%.
When I remove the music from the scene, the error does not disappear. I am now unable to actually play the game I've made because of this. This is extremely weird, because the content of the game is exactly the same, and it was working perfectly until about an hour ago. Is there anything I can do about this?
EDIT: I've found this appears to be related to a Video Player system I've built. Since I'm using Unity Indie, I can't use movie textures, so I constructed my own filetype which allowed me to stream a series of JPG images as textures to display. This seems to occasionally throw an Overflow error, and when it does and is allowed to terminate the script, the game will load. Otherwise, it seems it won't.
I appear to have fixed this by using an intermediate loading scene, rather than directly loading the level from the previous scene. It looks like it was related to the video player only in that the video player has a high memory footprint. I'll test a bit more, and see what happens.
If you find the answer, just answer your own question so people can find it easier. :)
I usually do. I haven't this time because the error was intermittent, and I'm not certain it's actually been fixed.
Nope, this error is still occurring. It's a bit weird. Sometimes I get this error every time I load a level, change something, then it all works, and then the error reappears without me changing anything.
Have you tried to stop all other non essential apps like skype to free up ram, that could help! If Unity has not changed then something else may have and there is lots of other stuff happening on a windows machine at any given time..
Answer by ricardo_arango · Jan 20, 2015 at 06:59 PM
Just a guess, but if you are creating your own Texture2D objects via script for each frame of video, make sure to Destroy them when you are done using them calling Destroy(). They are automatically destroyed when you change scene (if you are not referencing them statically or by an object marked with DontDestroy), but at that point you may already be using too much memory.
This is exactly what I was just trying. It seems to work, as Unity is now peaking at around 450$$anonymous$$B memory usage rather than 2GB, which is a lot more acceptable.