Hi, I have world generation that stalls the main thread so I’d like to put it in a job.
(So an animated loading bar can be used)
However I’m running into some problems with passing objects into the Jobs:
-
The noise generator is a configurable component. I can’t pass it or it’s transform to the job, for the noise generation.
-
I have a database of tiles that I need to pass to the job, so when it generates & map, it knows what color/images to use.
-
I wish to pass a callback so the job can update the main thread with it’s progress.
How can I get around these limitations?
Thanks!
You would need to use thread-safe types: Unity - Manual: Thread safe types
Though I don’t think you’d use a job for the whole thing. As I understand jobs should be for small, quick operations. As it states in the docs, you should avoid long jobs: Unity - Manual: Create and run a job (down the bottom of the page).
I would space out the various stages of the proc-gen with a coroutine or async code, myself. Or give it a time budget before it yields until the next frame. Then jobs/burst can be used for some of the number crunching stuff inside the world generation.
3 Likes
Ah I was thinking that, though adding awaits at certain intervals does dramatically increase the generation time, at least it’ll allow some frame updates and reduce headaches lol.
Thankyou for the helpful tips