#Threading
1 messages · Page 1 of 1 (latest)
I see... I can do some work on another thread, that's true. But to what extent can I stay on a background thread?
Can I create meshes and things on a background thread but need to come back to main thread to instantiate GameObjects?
Last I checked, no; almost any Unity API call needs to be on the main thread, outside of their specific job APIs.
That said, some Unity work can be done in a multithreaded way; for example you can load a texture file into CPU memory (on another thread), create a Texture2D (on the main thread, but this should be quick), start a background copy of the image data from CPU memory into that texture (I think? I know you can do this the other way around), then don't wait on that and start doing your next task.
So in theory the only step of that that has to be on the main thread is creating the Texture2D object (and requesting the copy to GPU). That has to be done on the main thread, and it will need to wait for a synchronisation point to do so, so ideally you would queue up a bunch of them and do them all at once the next time you get some time on the main thread.
I see... so there's no silver bullet like I thought... Thanks!
I'll do some research on this topic
I don't think so? Obviously Unity will do its own loading in efficient ways, but if you're writing your own code to load assets in non-Unity formats then as far as I know you're going to need to the hard work yourself.