I am currently working on a Voxel type game and I am wondering, Is there a way to call the complete event for a backgroundworker thread on the unity thread itself? I am running into errors when my thread tries to call unity functions from its completed event handler function. Is there a way to call an event for a thread finishing on the Main thread without blocking it using Join()?
I need to use threading because terrain generation is very intensive and causes many hiccups to the graphics. If this is not possible, are there any other alternatives to asynchronously generate data in the background AND catch it finishing?
This post can actually answer your question on threding and unity api. As far as i understand you cannot have a thread communicate with the api. You can probably try generating the data using compute shaders and then bind it to an object to render the terrain, the other thing could do, although i’m not sure that will work so you could try it, is to create data on a separate thread using your own functions to create data to then pass to the variable that is going to be use by the api. I’ve done something similar when working with UIs in .NET and i used delegates but i dont know if unity supports those
Edit: forgot to add the link to the post Threading in Unity - Unity Answers