When are materials loaded?

I’m having some strange glitches in my game, glitches which only appear on the iPhone (not the editor).

I’m doing 2D animation, so I’m cycling thru materials for each animation “frame”. I have a script that changes the material every .3 seconds or so.

The first time an animation plays, the fps drops considerably, but after that the animation plays fine.

I’m wondering if maybe the materials aren’t loaded until the first time they are used? This might explain the slowdown.

If so, is there a way to force them to load at game start?

I dont know when the maerials are exactly loaded but there are 2 workarounds.

First you can set all materials behind the background of your scene so that they are in the camera frustum. This forces the materials to load.
An other way would be to use just one material and animate it through uv-mapping the object.

Wouldn’t this use extra draw calls? I guess I could destroy the objects after the materials load?

Unfortunately, I’m not a 3D modeler, and know next to nothing about UV mapping!

Instantiating and then destoying objects with your materials on them behind a curtain of some sort (a loading screen) would do the trick. It’s kind of a cheesy workaround, but that’s what I did in Zombieville to load all of my big textures in advance. To answer your question - textures are loaded into memory the first time they enter the camera’s field of view, even if they’re behind something.

Thanks. I was afraid the slowdown was caused by some “quirk” in my code, but this should be a relatively easy fix. I needed to put in a title screen anyway, so I’ll hide a bunch of objects behind it, load all the materials, and then switch to the next scene.