Can anyone explain to me how to correctly use the job system on a specific simple example:
void Update()
{
Vector3 position = transform.position;
if((position - Toolbox.PlayerTransform.position).sqrMagnitude <= Toolbox.CollisionDistanceSqr)
{
Toolbox.PlayerTakeDamage(1);
m_Renderer.enabled = false;
m_Particle.Play();
enabled = false;
}
}
I’ve learned the hard way that with Unity you can get something to work only to later discover you’ve been doing it completely wrong the whole time.
What this function does should be fairly self-explanatory, but I’m not sure how to utilize jobs here. I can’t disable components or activate particle systems inside a job, correct? Can external static functions be called inside a job? How about accessing static variables? In the example above I’m accessing a static variable to test distance and calling a static function as well, both aren’t allowed for jobs right?
If I understand correctly the only thing parallel jobs can help me with(in this example) is forming a large list of objects that have passed the distance test against the player. I will then need to act out all the object-manipulating based on the results of the list. Is this statement true, or can something else be done with jobs here?
This example aside, can mesh batching using Mesh.CombineMeshes be done in a job? Can I make use of jobs for physics(without writing my own physics system)?
It seems to me that jobs have a fairly limited application in real game projects because they are for calculations only. The parallel computation benefits are greatly reduced by the fact that you will need to do “housekeeping” in the main thread after the jobs have finished, and most of the time you will still iterate the list of active objects - the thing you wanted to avoid by using jobs in the first place.