Major Memory Problems with using Lots of Movie Textures in a Scene

Hi,

I have a project with 300 Movie Textures (each fairly small – a few MB).
In my scene I have an object with a script which has a MovieTexture array, so I can point to the different movie textures and then stick the correct one on a texture to play when I need to.

I’ve added about 200 of the 300 movies and Unity has started crashing – to the point where I can’t save the scene or click around without getting a memory related crash.

An empty scene in another project sees Unity using about 100mb of memory, but when this scene crashes it’s running to about 2gb.

Do Movie Textures all get loaded into memory when they’re in a scene? Does adding them to a script array force them into memory? Is it wrong to have an array to reference them? Is there a better way to do this – I had assumed they just streamed off the disk as and when needed…

–Sam

Yes. All objects referenced in a scene/prefab through an array or other variable will be loaded into memory when the scene/prefab is loaded. The solution is to use Resources and load each MovieTexture when needed. So instead of an array with the movieTextures, you create an string array with the name of the movies and use that name to load them.

Excellent, cheers GameVortex!

Before I saw your message I solved this a slightly different way – I ended up converting the movies to .ogv myself and sticking them in StreamingAssets and then using WWW.movie to grab them from a string array for the filenames. I’m assuming this is essentially the same solution.

For the sake of anyone who might have done similar, I’ll note that I had issues with the .ogvs running on my Mac – they would always skip the first few seconds and show black screen whilst playing the audio. I’ve seen several instances of this reported elsewhere in other questions. My diagnosis was that the conversion via Mira Converter was causing problems. I switched to FFMPEG2THEORA and ran a batch conversion with that – problem eliminated.