Search Unity

How Physics work on Hybrid ECS?

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

  1. mentorgame1

    mentorgame1

    Joined:
    Oct 31, 2016
    Posts:
    19
    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

    GliderGuy

    Joined:
    Dec 14, 2018
    Posts:
    28
    (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

    Bhakti_GL1

    Joined:
    Jul 4, 2018
    Posts:
    17
    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

    Vacummus

    Joined:
    Dec 18, 2013
    Posts:
    77
    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

    GilbertoBitt

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

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,411
    GliderGuy likes this.