Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How Physics work on Hybrid ECS?

Discussion in 'Data Oriented Technology Stack' started by mentorgame1, Dec 18, 2018.

  1. mentorgame1


    Oct 31, 2016
    this is a questions that appear in my mind this day, how it will work OnCollisionEnter, OnCollisionStay, OnCollisionExit, OnTriggerEnter, OnTriggerStay, OnTriggerExit on Hybrid ECS? and what about OnEnable and OnDisable and Start, that i use so much with InControl?
  2. GliderGuy


    Dec 14, 2018
    (Someone slap me if I'm wrong) but I believe the physics (and its related functions) will work exactly the same. The real issue is using physics with the job system since there is no easy way to get or set a rigidbodies properties due to them being inaccessible from inside a job. When a systems job wishes to modify the transform, (using UnityEngine.Jobs's) TransformAccesArray can be used to bypass this restriction. But sadly, as far as i know there is no "RigidbodyAccessArray". So if you want to modify any of a rigidbodies respective variables while inside a job the only way to do this is to "offload" the processed data from the job back onto the main thread so you can have access to the required components... Which i do not know how to do. (Does anybody know how to do that?)
  3. Bhakti_GL1


    Jul 4, 2018
    I have a "Super duper tricky" way that I'm using for unity Physics implementation on ECS. Every entity (Parent) have a child that controls physics event like OnCollision, OnTrigger, etc. The parent (Entity) controlled by Job System, and the children (GameObjectEntity) controlled by Component System. They communicating physics interaction using colliding or trigger event that sent by the child to its parent.

    I implement this "Super duper tricky" way for 2d sprite animation and animation event too. I hope that this will help you a bit :)
    (and, someone please slap me if I'm wrong too) :D
    GilbertoBitt and GliderGuy like this.
  4. Vacummus


    Dec 18, 2013
    What @Bhakti_GL1 shared is a great approach that I have used for some of my use cases. Another approach that I have been using recently is creating a separate entity as an event, and then using "ComponentDataFromEntity" to get the data I need by entity id. Like for example, when an organism wants to eat another organism and it's mouth collides with it, I create an entity with a component called "struct EatOrganism: IComponentData { Entity from, Entity to }". I tend to alternate between the two approaches depending on my use case, though I would like to do some benchmark testing to see what the performance implications are of these two approaches.
    Last edited: Dec 19, 2018
  5. GilbertoBitt


    May 27, 2013
    amazing, i will try one of these things right now to see if it work!
  6. Antypodish


    Apr 29, 2014
    GliderGuy likes this.