- Home /
Intermingled Read and Render?
Here, we're reading a text file for coordinate data. We'll want to generate meshes and render them. (or use prefabs)
Is there a way to instantiate and render as we read along? Rather than read everything and then render everything? So, we get a sort of "popping" effect.
Although I haven't used them, I'm guessing this is a coroutine deal where the reading is held up while the render is done?
thanks
Answer by Statement · Mar 07, 2011 at 12:23 AM
- You could make use of threads for the file access if you need this to be done runtime.
- You could amortize the construction of meshes early and create a list of Meshes.
A coroutine might work if you use the WWW class. Otherwise a coroutine won't be of much use unless you load a few bytes each time.
If you need to continuously stream data, I think a thread could be proper. That way the rest of the game continues even if the load takes some time.
Yeah, that's basically what I'm getting at. I'd like to start rendering with some of the data to keep the user's attention while the code reads/processes the bulk of the data.
Yes, it looks like threads is what I'm after. I never done used no threads before! I'm frightened!
Using threads is quite easy with .net. Synchronizing data between threads can become a bit trickier. Also note most unity methods aren't usable from another thread. One way I prefer is to have a synchronized queue. A thread produce something, puts it in the queue and continues producing something more. The main thread can then check each frame if there is anything in the queue and take it.
Answer by Eric5h5 · Mar 07, 2011 at 12:59 AM
Unless you have a massive amount of data or your code is bad, it would only take a fraction of a second anyway, so it's unlikely you need to worry about it.
hmmm... it's less about the read time and more about some of the processing of the data prior to rendering. Upwards of 2 $$anonymous$$utes.
Your answer