Hiya,
I’m trying to combine some PhysX and ECS features.
Specifically, I’m scheduling some jobs from a ISystem. It’s great that I can schedule jobs straight from a bursted ISystem.OnUpdate!
However, RaycastCommand.ScheduleBatch doesn’t work from a bursted job.
/// Conceptual demo:
[BurstCompile]
public partial struct CastSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
JobHandle dep = state.Dependency;
// Allocate some arrays for the commands & results
var raycastCommands = new NativeArray<RaycastCommand>(32, Allocator.TempJob);
var castHits = new NativeArray<RaycastHit>(32, Allocator.TempJob);
// Generate commands.
dep = new GatherCommands
{
Raycasts = raycastCommands,
}.ScheduleParallel(query, dep);
// Execute raycasts.
dep = RaycastCommand.ScheduleBatch(raycastCommands, castHits, 32, 1, dep);
state.Dependency = dep;
raycastCommands.Dispose(dep);
castHits.Dispose(dep);
}
}
/// Error:
(0,0): Burst error BC1040: Loading from a non-readonly static field `Unity.Jobs.LowLevel.Unsafe.BatchQueryJobStruct`1<Unity.Jobs.LowLevel.Unsafe.BatchQueryJob`2<UnityEngine.RaycastCommand,UnityEngine.RaycastHit>>.jobReflectionData` is not supported
at Unity.Jobs.LowLevel.Unsafe.BatchQueryJobStruct`1<Unity.Jobs.LowLevel.Unsafe.BatchQueryJob`2<UnityEngine.RaycastCommand,UnityEngine.RaycastHit>>.Initialize()
at UnityEngine.RaycastCommand.ScheduleBatch(Unity.Jobs.JobHandle* $___struct_ret, Unity.Collections.NativeArray`1<UnityEngine.RaycastCommand>* commands, Unity.Collections.NativeArray`1<UnityEngine.RaycastHit>* results, int minCommandsPerJob, int maxHits, Unity.Jobs.JobHandle* dependsOn)
at PackageResolveSystem.OnUpdate(PackageResolveSystem* this, ref Unity.Entities.SystemState state) (at C:\Users\A-Bru\Footlong\Assets\Postal\PackageResolveSystem.cs:208)
at PackageResolveSystem.__codegen__OnUpdate$BurstManaged(System.IntPtr self, System.IntPtr state)
at PackageResolveSystem.__codegen__OnUpdate_000000A7$BurstDirectCall.Invoke(System.IntPtr self, System.IntPtr state)
at PackageResolveSystem.__codegen__OnUpdate(System.IntPtr self, System.IntPtr state)
I don’t have a good sense of whether that’s a very fundamental limitation, or something that COULD work. Given that other jobs can be scheduled from a bursted function I assume this is some difference for these ‘custom’ jobs.
Hopefully this could be fixed, or any advice much appreciated!