I’m trying to bake my meshes on a different thread with Unity jobs mainly going off of this page in the Unity docs. My code looks like this:
public struct BakeJob2 : IJob
{
public int meshId;
public void Execute()
{
Physics.BakeMesh(meshId, false);
}
}
and calling the job like this:
NativeArray<int> meshId = new NativeArray<int>(1, Allocator.TempJob);
meshId[0] = mesh.GetInstanceID();
var job = new BakeJob2();
job.meshId = meshId[0];
job.Schedule().Complete();
meshId.Dispose();
meshCollider.sharedMesh = mesh;
My profiler looks like this:
As you can see, Physics.BakeMesh is still running on the main thread, my other “jobs” threads are on idle. So I think my job is just not executing and the Physics.BakeMesh is getting called from the meshCollider.sharedMesh = mesh. If the mesh data is already available it won’t rebake the mesh. I think there are a few things I am probably doing wrong but I should at least get the thread to run before going further. What am I doing wrong? Thank you.