To detect collisions between two objects, I’m following this thread ( link ), using the format that @Bas-Smit recommends. The recommended approach agrees with the official code samples (link1, link2). However, in a vanilla project, I receive the following error, repeated at every timestep. Am I breaking convention or mis-setting up my entities somehow?
full trace
InvalidOperationException: The previously scheduled job System:CollisionEventJob reads from the Unity.Collections.NativeArray`1[Unity.Physics.Velocity] CollisionEventJob.EventReader.m_InputVelocities. You are trying to schedule a new job Solver:ParallelApplyGravityAndCopyInputVelocitiesJob, which writes to the same Unity.Collections.NativeArray`1[Unity.Physics.Velocity] (via ParallelApplyGravityAndCopyInputVelocitiesJob.InputVelocities). To guarantee safety, you must include System:CollisionEventJob as a dependency of the newly sche
Unity.Jobs.LowLevel.Unsafe.JobsUtility.ScheduleParallelFor (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters, System.Int32 arrayLength, System.Int32 innerloopBatchCount) (at <640657a3133d4ea99521a19cbe77e665>:0)
Unity.Jobs.IJobParallelForExtensions.Schedule[T] (T jobData, System.Int32 arrayLength, System.Int32 innerloopBatchCount, Unity.Jobs.JobHandle dependsOn) (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/Managed/IJobParallelFor.cs:52)
Unity.Physics.Solver.ScheduleApplyGravityAndCopyInputVelocitiesJob (Unity.Collections.NativeArray`1[T] motionVelocities, Unity.Collections.NativeArray`1[T] inputVelocities, Unity.Mathematics.float3 gravityAcceleration, Unity.Jobs.JobHandle inputDeps, System.Int32 threadCountHint) (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/Dynamics/Solver/Solver.cs:167)
Unity.Physics.Simulation.ScheduleStepJobs (Unity.Physics.SimulationStepInput input, Unity.Physics.SimulationCallbacks callbacksIn, Unity.Jobs.JobHandle inputDeps, System.Int32 threadCountHint) (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/Dynamics/Simulation/Simulation.cs:363)
Unity.Physics.Systems.StepPhysicsWorld.OnUpdate () (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/ECS/Systems/StepPhysicsWorld.cs:100)
Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/SystemBase.cs:414)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystemGroup.cs:445)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystemGroup.cs:450)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystemGroup.cs:398)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystem.cs:109)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ScriptBehaviourUpdateOrder.cs:192)
Setup for the vanilla project: There is one dynamic 1x1x1 cube. There is also one static (or kinematic, I tried both) 10x1x10 cube. There is also only one system, and its source is below. I attempted to force all previous physics jobs to finish, per this post ( link ), but the fix didn’t work; source for this attempt is also below.
System.cs
using Unity.Entities;
using Unity.Physics;
using Unity.Physics.Systems;
// Got basic structure of colliders from https://discussions.unity.com/t/783291
[UpdateAfter(typeof(EndFramePhysicsSystem))] // Also tried other orderings, for ex https://discussions.unity.com/t/737723/4
public class System : SystemBase
{
StepPhysicsWorld StepPhysicsWorld => World.GetOrCreateSystem<StepPhysicsWorld>();
BuildPhysicsWorld BuildPhysicsWorld => World.GetOrCreateSystem<BuildPhysicsWorld>();
struct CollisionEventJob : ICollisionEventsJob
{
public void Execute(CollisionEvent evt)
{
UnityEngine.Debug.Log(evt);
}
}
protected override void OnUpdate()
{
Dependency = new CollisionEventJob().Schedule
(
StepPhysicsWorld.Simulation,
ref BuildPhysicsWorld.PhysicsWorld,
Dependency
);
}
}
System.cs (fix attempt)
using Unity.Entities;
using Unity.Physics;
using Unity.Physics.Systems;
// Got basic structure of colliders from https://discussions.unity.com/t/783291
[UpdateAfter(typeof(EndFramePhysicsSystem))]
public class System : SystemBase
{
EndFramePhysicsSystem EndFramePhysicsSystem => World.GetOrCreateSystem<EndFramePhysicsSystem>();
StepPhysicsWorld StepPhysicsWorld => World.GetOrCreateSystem<StepPhysicsWorld>();
BuildPhysicsWorld BuildPhysicsWorld => World.GetOrCreateSystem<BuildPhysicsWorld>();
struct CollisionEventJob : ICollisionEventsJob
{
public void Execute(CollisionEvent evt)
{
UnityEngine.Debug.Log(evt);
}
}
protected override void OnUpdate()
{
EndFramePhysicsSystem.GetOutputDependency().Complete();
Dependency = new CollisionEventJob().Schedule
(
StepPhysicsWorld.Simulation,
ref BuildPhysicsWorld.PhysicsWorld,
Dependency
);
}
}
To reproduce: I’ve attached the Unity Project’s entire Assets/ folder. Below is also a screenshot of all packages installed + versions. I’m on Unity version 2020.1.0b7.
packages installed
Any pointers for where to look would be much appreciated. In case more context is helpful: I’m trying to get the amount of force that one cube hits the other with. Naturally, the first step is to figure out when one cube touches the other, but seems like I’m making mistakes already xD
6054335–655112–Assets.zip (8.08 KB)