Search Unity

Several collider questions

Discussion in 'Physics' started by MV10, Jan 23, 2016.

  1. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    All colliders in my scene are kinematic triggers. Basically the parent objects are ship hulls, and the child colliders are convex mesh firing arcs used to detect enemies in range.

    Edit: Disregard the first question... one object's rigidbody was accidentally un-checked in Inspector. Doh!
    The first question relates to compound colliders and static vs dynamic treatment. If I understand compound colliders correctly, a parent object should have a rigidbody (and possibly its own collider, yes?) but child objects can have colliders without their own rigidbody components. I thought that would result in the child colliders being dynamic, but when I watch the profiler, they're listed as static. Adding a rigidbody to the child colliders makes them show up as dynamic. Am I incurring a performance penalty if the child colliders in a compound hierarchy are static and/or do not have rigidbody?

    The second question relates to mesh collider performance. I understand primitive colliders are very highly optimized. In my case I need firing arcs of a certain shape and range. My mesh colliders tend to consist of just a handful of triangles, though they can be relatively large. Think flattened pyramids and low-poly cones. Is there much of a performance hit using a very simple mesh collider versus the primitive colliders?

    The last question relates to sleeping rigidbodies. I set the physics sleep threshold to zero so I won't have problems with trigger events firing (they did not fire prior to changing that setting, and I didn't want to constantly call WakeUp), but profiler still shows that some rigidbodies are sleeping. I don't understand why they're sleeping, and I don't understand why this doesn't cause problems with the events. I am vaguely guessing PhysX is doing some optimization based on the layer collision matrix and keeping the minimal necessary rigidbodies active, but that's just a completely wild guess.
     
    Last edited: Jan 23, 2016
  2. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    A simple answer: test it.
    A long answer:
    1. mesh collider needs to subdivide itself into triangles which takes a lot of time to sort and process during loading.
    2. mesh collider is essentially same as a lot of triangle colliders with simple culling. So in same use case runtime it should have approximately same performance as same amount of triangle colliders. No way to know exactly how much in your case unless you test it. If you have less triangles than mesh collider generates, that'll often be performance increase(but depends as well especially on triangle count).
    3. In very simple mesh collider you won't notice performance difference anyway unless you have tons of them.
    Because trigger is called from collider that's not sleeping when it collided into something(sleeping rigidbody included). By default two sleeping colliders shouldn't ever collide - that's why they sleep thus skipping calculations. In optimal bugless environment, there should not be problem with triggers and sleeping rigidbodies at all; as for actual reason, it depends.
    Threshold is maximum speed needed for them to sleep. If it's 0 and object is sleeping then maybe your object has absolute 0 velocity so it fell asleep?
     
  3. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    The documentation says "energy threshold below which a non-kinematic Rigidbody may go to sleep."

    It sounds as if it must be less than zero to sleep, and since they're kinematic, I didn't expect them to sleep at all. They don't stay asleep for long, I only see a very brief uptick in the Profiler counter.

    I added a bunch of logging and I can see no rhyme or reason for it. Sometimes I'll have 8 or 10 things flying around all awake for several minutes. Then in another test I just ran, the third object created was awake for a few seconds, then began switching back and forth between sleep and awake on every other frame. It did that for about ten seconds, then remained awake thereafter. None of the objects were anywhere close to colliding with one another.