Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Question Where can I start to work on the physics?

Discussion in 'Physics for ECS' started by iamshenkui_gee, Jun 24, 2022.

  1. iamshenkui_gee


    Apr 24, 2021
    I am using Unity DOTS to work on my own 2D games. However, I was stuck in the physics system for several days. The official samples provide samples of stateful projects, which is not really necessary for me at this time. Thus, I am wondering how can I find a new example for the collision system.
  2. cdytoby


    Nov 19, 2014
    They update their project recently often, and I'm looking at it, just like you, I'm confused by the way it handles, but I think I cleared part of it out already.

    Basically you need Physics Shape (collider) and Physics Body (rigidbody) on your gameobject (which will be turned into Entity). Then physics will do it's magic.

    If you want to retrieve event, you need to have a Job, inherited from ICollisionEventsJob, and schedule it after physics "update" (yourJob.Schedule(m_StepPhysicsWorld.Simulation, Dependency); ). And you need to process whatever you want inside that job.

    I'm still working on how to get collision position though.

    And also, the documentation is not clear.


    I'm stuck with this:

    Code (CSharp):
    1. InvalidOperationException: The previously scheduled job Solver:ParallelApplyGravityAndCopyInputVelocitiesJob writes to the Unity.Collections.NativeArray`1[Unity.Physics.Velocity] ParallelApplyGravityAndCopyInputVelocitiesJob.InputVelocities. You are trying to schedule a new job CollisionCollectJob, which reads from the same Unity.Collections.NativeArray`1[Unity.Physics.Velocity] (via CollisionCollectJob.EventReader.m_InputVelocities). To guarantee safety, you must include Solver:ParallelApplyGravityAndCopyInputVelocitiesJob as a dependency of the newly scheduled job.
    2. Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters) (at <4a31731933e0419ca5a995305014ad37>:0)
    3. Unity.Physics.ICollisionEventJobExtensions.ScheduleUnityPhysicsCollisionEventsJob[T] (T jobData, Unity.Physics.ISimulation simulation, Unity.Jobs.JobHandle inputDeps) (at Library/PackageCache/com.unity.physics@0.51.0-preview.32/Unity.Physics/Dynamics/Simulation/ICollisionEventsJob.cs:83)
    4. Unity.Physics.ICollisionEventJobExtensions.Schedule[T] (T jobData, Unity.Physics.ISimulation simulation, Unity.Jobs.JobHandle inputDeps) (at Library/PackageCache/com.unity.physics@0.51.0-preview.32/Unity.Physics/Dynamics/Simulation/ICollisionEventsJob.cs:45)
    5. SpawnBallSystem.OnUpdate () (at Assets/SpawnBallSystem.cs:61)
    6. Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/SystemBase.cs:409)
    7. Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystemGroup.cs:583)
    8. UnityEngine.Debug:LogException(Exception)
    9. Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/Stubs/Unity/Debug.cs:19)
    10. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystemGroup.cs:588)
    11. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystemGroup.cs:529)
    12. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystem.cs:114)
    13. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystemGroup.cs:583)
    14. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystemGroup.cs:523)
    15. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ComponentSystem.cs:114)
    16. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.51.0-preview.32/Unity.Entities/ScriptBehaviourUpdateOrder.cs:426)
    Last edited: Jul 5, 2022