Search Unity

CollisionEvents in Unity.Physics

Discussion in 'Entity Component System' started by Leuthil, Mar 23, 2019.

  1. Leuthil

    Leuthil

    Joined:
    Jul 26, 2013
    Posts:
    97
    I am trying to learn more about how to detect and apply game logic based on collisions in Unity Physics. There's not really any documentation about it other than this small snippet:
    I then searched the entire codebase for CollisionEvent. The only example I can find it being used is in the DisplayCollisionEventsSystem, where it's supposed to output when collisions happen. I tried to create and enable this system manually to see collisions but I am not receiving any info about collisions (maybe I have no idea what this system is actually supposed to do). I also copied most of the code and put some log statements for each collision event that the Simulation has registered, but it always seems to have no collision events even though in my game, bodies are clearly colliding and reacting to collisions (and those bodies have materials which have EnableCollisionEvents set). Does anyone have any idea what I'm missing?
     
  2. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
  3. Leuthil

    Leuthil

    Joined:
    Jul 26, 2013
    Posts:
    97
    Unfortunately I'm basing my code off of that example (except the collision one, not trigger).

    Edit: After trying those code changes (I'm using CollisionEvents and realized the code changes also impact them and not just Triggers), it does seem to be coming through now. Thanks.
     
    Last edited: Mar 23, 2019