Hello
Right now I’m working on a small car game in the dots + physics world. But my profiler showed, that my vehicleMechanic job is taking a lot of time ingame.
So far I did it in a pure ECS way, related to this approach of a vehicleMechanic job of the UnityPhysicsSamples RaycastCar, just a bit simplified.
Now I wanted to implement parallel execution & Burst to improve the performance, but then a lot of questions stacked up:
- Solved: In the RaycastJob, it does a JobHandle.Schedule() for a IJobParallelFor job. Does it mean that it can be executed in parallel? Because in the Entities.ForEach() you have to write ScheduleParallel() instead of Schedule() to run it parallel, right!?
- Open: If I execute the vehicleMechanic job with Burst, it will fail with
“Burst error: The managed class typeSystem.IntPtr
is not supported. Loading from a non-readonly static field is not supported” for
JobHandle rayJobHandle = ScheduleBatchRayCast(world.CollisionWorld, rayInputs, rayResults);
rayJobHandle.Complete();
(this specific job is also mentioned here & in the previous linked UnityPhysicsSample job)
I get the point, that I’m not allowed to get the results via pointer/reference on rayResults with Burst. But which options I have? Since Schedule() does not return something or so… I have to go the way with a pointer I guess, so how do I fix it? I could create a extra job without Burst, just for the execution… then save the results in a dynamicBuffer & access it again in the “vehicleMechanic” job… would this be the right way?
- Solved: Another thing is parallism. I have multiple cars in the scene, so it would be perfect if I could run the vehicleMechanic job in parallel. But it will already fail in this line:
int ceIdx = world.GetRigidBodyIndex(ce);
“The previously scheduled job VehicleMechanicSystem […] writes to the NativeArray […] CollisionWorld.DynamicTree.BranchCount. You are trying to schedule a new job […] which reads from the same NativeArray. To guarantee safety, you must include Vehicl” (it does not display the full error).
This ceIdx is from the chassis, which is the physicsEntityBlock of the car, so all calculations of all the wheels are depending on this. Does it mean physics logic in general is not possible with parallism or how can I solve this problem?
I appreciate your help