Slight pause when loading a texture into memory 1st time

Hey all,

I have a menu system for my iPhone game made completely of planes in 3d space, lerping in and out of view. When I hit a button, new planes slide into view, with new textures on them. On the iPhone, right as the plane with a new texture slides into view, the game lags a small amount as it loads the texture into memory. If i then hide the menu then unhide it, this time the lerp is perfectly smooth, and from then on in the menus, no matter how many times I run the lerp animation, it is smooth. It’s that first time that kills framerate of the slide-in to the point where it just pops in. This cannot be seen on the PC.

I want to load all of the textures in the mainmenu into memory right in the beginning so that the first time it comes into view, it wont have to load again. I’m not sure how to do this and I’ve been trying to think up hacks to do so. I even tried putting a second camera into the scene and enabling it at start, for .5 seconds, and made sure the camera could see all of the textures, thus forcing them to load. I set this second camera’s depth to -10 so it doesnt render in front of the main camera and cause a disorienting flash. I have proved that the drawcalls go up during the time it is enabled but on the iPhone it does not help the stutter. Ideas?

What I did for Zombieville was have a group of planes with all of my textures on them hidden behind a “loading” screen, which was just a black polygon with some text and a little walking zombie. Since the textures were technically in view of the camera (although hidden behind something) they were still loaded into memory, and then I deleted them all a fraction of a second later.

I’m not sure why the dual camera trick you’ve described wouldn’t achieve the same result, as its kinda using the same principal.

So, did this black plane completely cover 100 percent of the screen with no alpha? And the textures were still loaded behind that?

And UT guys, is there no way to load a texture into memory before seeing it (programmatically?)

loading in memory is not the problem
but textures are not uploaded into graphics memory before beeing rendered at least once (or once again should it have been dropped out of graphics memory due to not beeing used while the memory was required for other textures) and thats what the “show behind loading screen” does and what you must do too

There’s frustum culling in there by default, so anything out of the camera view isn’t rendered (and hence not loaded into memory). NinjaPirateAlliance’s tactic is a simple clever way of making sure it’s loaded but not seen, as occlusion culling isn’t built in (although it’s very much possible) so anything behind another object is still loaded into memory, just obscured from view. His suggestion should solve your problem. Just make sure you don’t have animation on that first load, as the frame rate stutter as the textures are added to memory will still be noticeable.

There is occlusion culling on Unity iPhone you just have to setup and use it

Yeah, sorry, I didn’t mean to say there was no occlusion culling, just that it isn’t all set up when you create a new project, whereas frustum culling is.
:slight_smile:

Yes, it seems hacky but its effective. You should only have to do this for large, uncompressed textures though. My new game mostly uses 256x256 4-bit PVRTC textures for characters and effects art, and each one is so tiny (32k) that there’s no perceptible hiccup when they’re loaded the first time even on old iDevice models. The hiccup seems to only occur when you jam a half a meg of texture into view all at once, which is easily done with uncompressed UI elements.

That sounds like the story of my life/game. :stuck_out_tongue: Thanks, I’ll test it tonight.

Yep, that worked. Thanks guys.

Have you found that loading in multiple 256x256 textures was less laggy than one or two 1K textures?

I’m experiencing something similar, but it’s intermittent. The cause is Texture.AwakeFromLoad, but as I mentioned it doesn’t happen all the time. Any ideas on what’s causing this?

I’m not so sure bumping a thread from 2.5 years ago is the best way to ask the question. I’d consider making a new post with more details on your issue.