I had a hard time finding some examples of the job system, but finally I am starting to understand it, Here is an example script I made. It is probably not the most efficient use of the job system but atleast it should get you started Code (CSharp): using System.Collections; using Unity.Collections; using UnityEngine; using UnityEngine.Jobs; namespace Scripts { public struct MoveToTargetJob : IJobParallelForTransform { public float DeltaTime; public NativeArray<Vector3> Targets; public float Speed; // Called once per element in the TransformAccessArray public void Execute(int index, TransformAccess transform) { transform.position = Vector3.Lerp(transform.position, Targets[index], DeltaTime / Speed); } } public class TransformJob : MonoBehaviour { public int Count = 1000; // How many spheres you want to spawn public float Speed = 20; // The speed which the spheres moves public int SpawnRange = 50; // The range from -SpawnRange to SpawnRange private Transform[] _transforms; private Vector3[] _targets; public void Start() { // Create (count) amount of spheres _transforms = new Transform[Count]; for (int i = 0; i < Count; i++) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere); obj.transform.position = new Vector3(Random.Range(-SpawnRange, SpawnRange), Random.Range(-SpawnRange, SpawnRange), Random.Range(-SpawnRange, SpawnRange)); obj.GetComponent<MeshRenderer>().material.color = Color.red; _transforms[i] = obj.transform; } // initialize the targets array _targets = new Vector3[_transforms.Length]; StartCoroutine(GenerateTargets()); } // Generate targets, I was not able to use Random.Range inside the job system, so generate the outside public IEnumerator GenerateTargets() { while (true) { for (int i = 0; i < _targets.Length; i++) { _targets[i] = new Vector3(Random.Range(-SpawnRange, SpawnRange), Random.Range(-SpawnRange, SpawnRange), Random.Range(-SpawnRange, SpawnRange)); } yield return new WaitForSeconds(2); } } public void Update() { // Put the spawned transforms into a TransfromAccessArray TransformAccessArray transAccArr = new TransformAccessArray(_transforms); // Create a native array for _targets NativeArray<Vector3> nativeTargets = new NativeArray<Vector3>(_targets, Allocator.Temp); // Setup the job var job = new MoveToTargetJob(); job.DeltaTime = Time.deltaTime; job.Targets = nativeTargets; job.Speed = Speed; // Schedule the job job.Schedule(transAccArr); // Dispose of the arrays transAccArr.Dispose(); nativeTargets.Dispose(); } } }
You should add a job handle and then call complete on it. Otherwise, you get a lot of errors at runtime. Code (CSharp): var jobHandle = job.Schedule(transAccArr); jobHandle.Complete();
You can schedule a job anywhere on the main thread (you cannot schedule a job within a job - it’s somewhere explained in the docs)
Here is a repo with some more job system/burst examples: https://github.com/korzen/Unity3D-JobsSystemAndBurstSamples
If anyone is interesting about testing jobs. I have made something similar like @korzen303 with addition control. https://github.com/ErikMoczi/Unity.TestRunner.Jobs
Take a look at my repo for a couple of elementary samples: https://github.com/starikcetin/Learning-Unity-ECS
That's a very broad questions however NavMesh are supported via the experimental NavMeshQuery https://docs.unity3d.com/ScriptReference/Experimental.AI.NavMeshQuery.html Note you'll need to build your own NavMeshAgent