Ofx360
October 12, 2022, 4:40pm
1
So i setup this fairly simply script to try out IJobEntity (instead of the simpler foreach loop). After using ScheduleParallel() like in the docs, i decided to try Run() but started getting spammed with errors that i’m missing something even though this is the only system i have operating over this entity:
InvalidOperationException: The previously scheduled job Jobs:RecordDynamicBodyIntegrity reads from the ComponentTypeHandle<Unity.Transforms.Translation> RecordDynamicBodyIntegrity.JobData.PositionType. You are trying to schedule a new job TestJob, which writes to the same ComponentTypeHandle<Unity.Transforms.Translation> (via TestJob.JobData.__Unity_Transforms_TranslationTypeHandle). To guarantee safety, you must include Jobs:RecordDynamicBodyIntegrity as a dependency of the newly scheduled job.
Here’s the code:
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.Collections;
using Unity.Burst;
public partial struct SateliteSystem : ISystem
{
EntityQuery query;
public void OnCreate(ref SystemState state)
{
var builder = new EntityQueryBuilder(Allocator.Temp);
builder.WithAll<SateliteComponent>();
builder.WithAllRW<Translation>();
builder.WithAllRW<Rotation>();
query = builder.Build(ref state);
}
public void OnDestroy(ref SystemState state)
{
}
public void OnUpdate(ref SystemState state)
{
var dt = SystemAPI.Time.DeltaTime;
new TestJob{ deltaTime = dt }.Run(query);
}
}
[BurstCompile]
public partial struct TestJob : IJobEntity
{
public float deltaTime;
void Execute(ref Translation transform)
{
transform.Value += new float3(0, 1 * deltaTime, 0);
}
}
Here’s the full error:
InvalidOperationException: The previously scheduled job Jobs:RecordDynamicBodyIntegrity reads from the ComponentTypeHandle<Unity.Transforms.Translation> RecordDynamicBodyIntegrity.JobData.PositionType. You are trying to schedule a new job TestJob, which writes to the same ComponentTypeHandle<Unity.Transforms.Translation> (via TestJob.JobData.__Unity_Transforms_TranslationTypeHandle). To guarantee safety, you must include Jobs:RecordDynamicBodyIntegrity as a dependency of the newly scheduled job.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters) (at :0)
Unity.Entities.JobChunkExtensions.ScheduleInternal[T] (T& jobData, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode, Unity.Collections.NativeArray`1[T] chunkBaseEntityIndices) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/IJobChunk.cs:320)
Unity.Entities.JobChunkExtensions.Run[T] (T jobData, Unity.Entities.EntityQuery query) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/IJobChunk.cs:216)
SateliteSystem.OnUpdate (Unity.Entities.SystemState& state) (at Assets/Scripts/SateliteSystem.cs:28)
SateliteSystem.__codegen__OnUpdate (System.IntPtr self, System.IntPtr state) (at <58e20f4097624ce89f83af901be88548>:0)
Unity.Entities.SystemBaseRegistry+<>c__DisplayClass9_0.b__0 (System.IntPtr system, System.IntPtr state) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemBaseRegistry.cs:228)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.<>c__DisplayClass9_0:b__0(IntPtr, IntPtr) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemBaseRegistry.cs:232)
Unity.Entities.UnmanagedUpdate_00001487$BurstDirectCall:wrapper_native_indirect_000002F0BCD4B868(IntPtr&, Void*)
Unity.Entities.UnmanagedUpdate_00001487$BurstDirectCall:Invoke(Void*)
Unity.Entities.WorldUnmanagedImpl:UnmanagedUpdate(Void*) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/WorldUnmanaged.cs:801)
Unity.Entities.WorldUnmanagedImpl:UpdateSystem(SystemHandle) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/WorldUnmanaged.cs:866)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ComponentSystemGroup.cs:664)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ComponentSystemGroup.cs:628)
Unity.Entities.SystemBase:Update() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemBase.cs:406)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)
You have to call state.CompleteDependency();
before running a job in a struct implementing ISystem
Ofx360
October 12, 2022, 5:14pm
3
Great, that does stop the errors!
And I’m guessing this is just for when i’m using Run(), not when i’m using the various Schedule…() methods?
Not seeing much info on this (or ISystem) on the docs