Search Unity

Layers not impacting performances

Discussion in 'Physics' started by TheTortilla, Jan 7, 2018.

  1. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    Hi everyone,

    here is my issue:

    Layers don't have impact on performances, when I put objects in layers that should not interract with each other in the "layer collision matrix" they are obviously not colliding with each other, but the collisions tests are still performed by Unity Engine/PhysX and can be observed in the profiler.

    This is okay if you want to make object oing through each nother and others not, but this mean that you can't use layers to optimize performances regarding physics in your game.

    Is there an other efficient way to disable completely the collision tests between layers to improve performances?

    Thank you for your help!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    They're not child objects or something like that, are they?
    Afaik, objects on layers that don't interact shouldn't be doing what you say you see happening.
     
  3. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,537
    How do you expect it to know if it is allowed to collide or not if it doesn't perform a test to see if it is allowed?
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I should add that my answer maybe didn't account for "some time to work out what's allowed/not", but meant to say that performance differences will exist beyond (that).
     
  5. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    Thank you for your answers!

    @methos5k
    They're not child objects

    @LaneFox
    I'm not surprised to see some time taken to see if collision should happen. I'm surprise to see no differences between physics time involved having 10000 objects moving that can collide(trigger) with each other and 10 000 objects that can't according to the collision matrix.

    testing collisions in Physic engine seem to create massive overhead on profiler (2-3 milliseconds in physics and about the same in scripts) when an object with a kinematic rigidbody moves near 10 000 objects it cannot collide with, same as when it can. This overhead disapear if the object has no rigidbody.

    My question could be asked this way:

    How can I prevent collision between objects not being tested with certain other objects to improve performances?
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, you're welcome for the answer, in the limited sense of helpful that it was :)

    The profiler does add some overhead, but what you're describing is essentially no difference for that many objects.. I've never tested it myself, just took it on samples posted (one from Unity, in fact, I believe) + 'faith' that that's not how it works/is supposed to be/work :) lol sorry.

    Perhaps someone else will offer some insight.
     
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Layers don't impact performance like you are thinking because regardless of what layer an object is in, the collision system still has to track it. Setting up layers so that objects don't interact doesn't mean they are not colliding, they are still colliding. It's just the physics system doesn't have to calculate depenetration and interaction when they do collide.

    Best thing is to just give us your actual use case, there are probably ways to make it perform better. Most likely by not actually having 10,000 rigidbodies in the scene. Most likely you don't actually need those.