Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Is multiple PhysicsShape(s) supported on the Entity?

Discussion in 'Physics for ECS' started by Bokus, Jul 19, 2021.

  1. Bokus

    Bokus

    Joined:
    Apr 28, 2014
    Posts:
    16
    Hello,

    I have a GameObject which is converted to an Entity and has several primitive (box) PhysicsShape components on it. When this is converted to an Entity, with OnUpdate System I only get once in the loop for PhysicsCollider.
    Can't visualize PhysicsCollider so I'm not sure if these boxes are merged to one collider or one of those PhysicsShapes is only taken in consideration?

    My goal is to go through all entities that have PhysicsShapes and do some calculation, when done per Entity I would tag them and not process them again. I tried also querying Entity with PhysicsBody instead of PhysicsShapes and then use EntityManager.GetComponentData, but this is also trying to extract single component, no array option?

    So my question is if more than one PhysicsShape is supported on the single Entity?
    If not I guess another approach would be to have an Entity for each simple box PhysicsShape instead of grouping them on one GameObject.

    Thanks!
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    If there are multiple PhysicsShape components on a GameObject then the individual colliders (e.g. BoxCollider) are collected into a single CompoundCollider. The CompoundCollider is then held by the PhysicsCollider component.
    The same happens for multiple PhysicsShape components in a hierarchy. All the PhysicsShapes are collected up to a parent node that is either at the root or has a PhysicsBody component. The '2a2. Collider Parade - Advanced' sample scene shows a number of hierarchy setups.
     
  3. Bokus

    Bokus

    Joined:
    Apr 28, 2014
    Posts:
    16
    Thanks for the clarification!

    I checked the example. If I understood correctly I won't be able to do what I want - to have all PhysicsShape components on one Entity since they will be combined.
    My use case is that I need to iterate over all simple box PhysicsShapes and do some calculations and feed it in another system.
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    You can get all the child shapes using the CompoundCollider->GetLeaves function, or if everything is flatten you could just loop over the CompoundCollider->Children array to get at the individual child BoxColliders. Looks like there is no direct example of this. We should look at that.