Author Topic: BoxCollider2D verification and UIRoot scale  (Read 3506 times)

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
BoxCollider2D verification and UIRoot scale
« on: November 26, 2014, 03:55:29 PM »
I've just encountered something unusual and would like to get your thoughts on way forward.

I've got buttons on my UI. I like to keep them relatively small - 20 -25 pixels square or so. They have 2D BoxColliders on them which are resized automatically depending on the widget's size. WHen I recently pushed MaximizeOnPlay to demo the UI, I found I could no longer detect these small buttons. It turns out the collider posted a warning in the collider inspector saying the physics engine had failed to validate it because it was too small. My screen height was 1040 (1200 less UnityEditor menu bars, etc.) and UIRoot's scale (flexible style as I'm on Windows and Mac platforms) was 0.00192307 which all makes sense.

After some experimentation, it seems that these colliders, when UIRoot reduces its scale to the value above, need to be a minimum of about 27-28 pixels in both x and y in order to validate.

Now of course I can simply increase the minimum size of all my sprites that contain colliders, but that seems like a temporary hack. Before I go down this route, I'd like to know your thinking on how this might be dealt with more systematically, assuming of course that you have encountered it before. I have found nothing in the forums to date on this, except acknowledgement in Unity that colliders can be too small and not validate.
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BoxCollider2D verification and UIRoot scale
« Reply #1 on: November 26, 2014, 08:45:13 PM »
Known issue with Unity's 2D physics.

Stick to 3D colliders.

NGUI menu -> Extras -> Switch to 3D colliders

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
Re: BoxCollider2D verification and UIRoot scale
« Reply #2 on: November 27, 2014, 07:31:41 AM »
Thanks for the insight.

Do you know if they view it as a bug to be fixed, or is this just a limitation of the NVidia physics engine that all will have to live with?

If they will eventually fix it, I'll defer switching over to 3D colliders for awhile.
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BoxCollider2D verification and UIRoot scale
« Reply #3 on: November 27, 2014, 08:57:23 PM »
2D physics uses Box2D, not PhysX, so whatever issue it is running into is likely in that library. I don't think it's something they're going to fix.

fur

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: BoxCollider2D verification and UIRoot scale
« Reply #4 on: April 02, 2015, 05:57:41 AM »
I just upgraded to NGUI 3.8 and trying out the Collider2D, and got the same problem.

It can be work around by putting a parent to UIRoot and set it's scale to >10, then resize the camera size accordingly.

Then it seems work but not thoroughly tested for any other problem, and it seems not a good practice anyway...

I wonder how much performance we can get and worth if we switch from Collider3D to Collider2D....

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BoxCollider2D verification and UIRoot scale
« Reply #5 on: April 04, 2015, 03:49:56 AM »
None you will ever notice. It makes sense to switch from 3D to 2D if you're doing actual collisions, but UI doesn't. It simply does raycasts.