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

Question Authoring ECS physics using built-in Physx

Discussion in 'Physics for ECS' started by chriscode, Aug 17, 2023.

  1. chriscode

    chriscode

    Joined:
    Mar 2, 2015
    Posts:
    44
    So I believe as of version 1 I can add RigidBodies to my "baker" sub-scene objects and these are converted appropriately for the ECS system at runtime.

    When I convert my Spheres in the Physics Samples Events - Collisons, to traditional RigidBodies, rather than PhysicsBodys things work as expected. However my floor HAS to remain as a PhysicsShape to trigger any collisions. I.E. I can't seem to convert that to a normal Box Collider (with or without a rigidbody), and still get events triggered.

    Q1) Because the PhysicsBody and Physics shape are now part of the samples package, I assume we're supposed to move towards authoring using the traditional RigidBody (this is implied in the docs), and allow the baking system to create the necessary ECS components?
    Q2) But then how do I get collision events without using the PhysicsShape/Body stuff?

    Sample used here:
    https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/PhysicsSamples



    upload_2023-8-17_16-52-14.png
    upload_2023-8-17_16-45-27.png
     
    layker90524 likes this.
  2. SergioTurGil

    SergioTurGil

    Joined:
    Mar 11, 2021
    Posts:
    2
    +1 (as of 1.0.14 this looks like a bug)

    RigidBodies are not raising CollisionEvents (TriggerEvents are raised correctly if the IsTrigger checkbox is checked).
    Also RigidBody constrains are ignored.

    This can be checked with a very simple test with two entities, one using Collider + RigidBody (doesn't work) and the other Physics Shape + Physics Body (does work but needs physics samples to be imported).

    It looks like Constrains are not being correctly baked into Intertia Tensors and the "Collision Raise collision Events" is not set either.
     
    layker90524 likes this.
  3. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    Thanks for reporting this feature gap.
    I can confirm that currently built-in physics only uses either
    CollisionResponsePolicy.Collide
    (default) or
    CollisionResponsePolicy.RaiseTriggerEvents
    (if the built-in collider's
    isTrigger
    property is true) as value for
    Material.CollisionResponse
    in the corresponding baked collider.

    In other words, unless you manually change this property in your Entities' baked collider components through a system post-baking (or via a baking system that runs after the EndColliderBakingSystem, you can not use the desired response type (
    CollisionResponsePolicy.CollideRaiseCollisionEvents
    ) for built-in colliders at this time.
    Note that this is not a regression but was simply never implemented.

    @SergioTurGil : To confirm my understanding, I assume you mean these Constraints, right?
    upload_2023-9-1_10-45-42.png
     
  4. SergioTurGil

    SergioTurGil

    Joined:
    Mar 11, 2021
    Posts:
    2
    @daniel-holz, thx for your response. Yes, those are the constraints I'm talking about.

    I'll try your workaround!
     
    daniel-holz likes this.