Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question what's the perf impact of enabling and disabling triggers?

Discussion in 'Physics' started by laurentlavigne, Oct 22, 2021.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    wondered if physx still rebuilds the entire world graph when that's done
    and if so, what's the best way to disable a trigger?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,497
    I haven't tested this explicitly (@yant could reply better to this), but I have a case where I need to disable and re-enable actual colliders in each frame for certain queries. The method I use is changing the layer in these colliders, run the queries, then restore the original layer. The same approach may be used with triggers. As for what I can tell, this method is essentially free.
     
    laurentlavigne likes this.
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    interesting method, I just freed up a layer so I might try that.
    do you know what the overhead would look like in the profiler?
     
    Edy likes this.
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,497
    I don't think that changing layers would even appear in the profiler. It's just changing a flag.
     
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    What about the overhead of turning on and off the collider? How do these things show up on the profiler?