I’m looking to stream in textures from disk while in the middle of a scene.
The game we are doing moves the camera through a long loop.
The art is stunning, and rather than reduce the texture sizes so that the entire scene fits in memory, we’d like to dynamically load and unload the textures as objects go out of view, and load them just before they’re needed.
I’ve sorted the objects into a list and am able to efficiently determine which objects are visible at any time in the loop.
Right now I’m loading the textures using Resources.Load() and it seems that no matter what I do, even using a Coroutine there’s a stutter when each texture is loaded.
Is there any way to load textures in the background safely without affecting the framerate?
Our game is done except for reducing the memory consumption. With everything preloaded we’re running around 60MB.
Any advice is greatly appreciated. I’ll be around on the boards to help in any way I can as well.
it will always stutter if the texture is not reasonably small and compressed and even then it does just that short that you don’t recognize it.
thats no unity thing but a technology thing of graphic cards on any platforms I’ve ever heard of
Yes, but you can lock just one section of vram and upload using DMA. It shouldn’t have to block.
Is that where the stutter is coming from?
I’m thinking it’s either:
- Resources.Load is going to block while reading from the disk. I’ve put this in a Coroutine, but I wonder if it would be possible to call it from a separate thread.
- When the data that’s loaded is saved to a texture object:
texture = (Texture)LoadResources(“TextureName”) as Texture;
or:
- When the texture is assigned to a material.
On the consoles I’ve always uploaded the next textures needed in the background and there’s no effect on the main thread.
Thanks for your answer. If Unity doesn’t handle this now, it’s something I’d really like to see in the future. It opens up possibilities.
Does anyone know of any way to load textures without stuttering?
well you seem to have a major missconception:
Coroutines run in the same thread as the rest of the engine, not async.
you can not use threads to talk to unity, it will bomb. Unity 2.6 Pro offers async ops from asset bundles but without a second processor / core, having async high performance file loading is as a bit useless, especially on a low speed device without out of order execution like the iphones cpu as apple went out with the old 3GS cpu on a higher clock again instead of finally integrating the new generation arm cpu from last autumn that has 2 cores and (much more important) out of order execution
Without async ops the way to go is: reduce the amount of data to load.
256 square 4bbp pvr compressed should not cause any problems normally for example.
also don’t attempt to do it with pre 3GS. it won’t do much there. CPU is too slow and chances that you run already on the ram border is very high, with OS4 actually near granted
Thanks Dreamora,
I am aware of the difference between threads and coroutines.
I’m not looking for a high performance file io, just a way to load a texture into memory asyncronously, even if it took a full second.
If there is DMA available on the iPhone it should be theoretically possible, but I’m not sure what the iPhone OS or Unity has implemented.
Anyways, I’m going to have to reduce the texture size and make the entire scene fit in RAM.
Thanks again for your help.
Have a great day!
Does anyone know if Unity 3 supports new asyncronous loading features?