Author Topic: Disappearing box colliders  (Read 5065 times)

Livealot

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Disappearing box colliders
« on: July 22, 2014, 07:46:21 PM »
I have some weird interactions happening between my NGUI objects and my gameplay objects.  For example, I can spin a cube and the box collider for one of my NGUI elements can get disabled by that spin.

So I'm guessing there is some physics based interaction that is happening where the collider of the gameplay object and the collider of the NGUI object collide in such a way as to disable the NGUI object.  So two questions…

Why/how could that happen?

How can I prevent?  Are there simple tips to keep the NGUI elements and the gameplay elements clearly separate within the scene?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disappearing box colliders
« Reply #1 on: July 22, 2014, 11:26:23 PM »
I see no reason why spinning a 3D cube would affect your UI in any way, especially if you're using NGUI's events to spin the cube (UICamera script attached to the main camera as well). All NGUI colliders are also created with trigger type colliders, so they won't interact with your game colliders. If nothing else, adjust the physics collision matrix and make sure that your UI layer doesn't interact with anything else. Edit -> Project Settings -> Physics.

Livealot

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Disappearing box colliders
« Reply #2 on: July 23, 2014, 12:48:47 PM »
I can't think of a reason either, which is why this is weird…but true.

I tried the physics collision matrix, but no effect.  Here are some more specifics that might help figure it out.

The spinning cube is part of gameplay and not the UI, and actually doesn't spin.  My gameplay camera actually spins 90 degrees around the stationary cube when I swipe.  My NGUI camera only renders NGUI objects, and my gameplay camera only renders gameplay objects.  So to be more accurate, when I spin my gameplay camera twice, some of the NGUI element box colliders get disabled.  And interesting to note that spinning just once does not disable that same component. My UICamera Event Type is set to 3DUI, and I do NOT attach UICamera script to my main gameplay camera, only my NGUI camera.

I've also noticed that other random NGUI components get disabled during runtime, like UIStretch and UIAnchor.  All the NGUI elements look right, but those components are also getting disabled somehow during runtime.

I'm using FingerGestures as input, so maybe that input is affecting NGUI somehow, in addition to the gameplay.

And my own gameplay camera script uses a StopAllCoRoutines() call as part of the spinning process.  So if NGUI uses coroutines, maybe that's what causes the random component disablement.
« Last Edit: July 23, 2014, 12:58:16 PM by Livealot »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disappearing box colliders
« Reply #3 on: July 23, 2014, 08:06:55 PM »
UIStretch and UIAnchor are legacy components that have been deprecated a long time ago. Are you using NGUI 2?

Livealot

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Disappearing box colliders
« Reply #4 on: July 23, 2014, 09:00:13 PM »
No, I'm on NGUI 3.6.7

I guess I wasn't working on my UI when you made the switch from UIAnchor/UIStretch to anchors in UIRect.  So that's good to know.

Has working with colliders changed too?  I now see under Extras something about switching to 2D or 3D colliders.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disappearing box colliders
« Reply #5 on: July 23, 2014, 09:29:59 PM »
Nothing has changed with colliders in a while. Support for 2D box colliders was added a while back, but that's about it.

Livealot

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Disappearing box colliders
« Reply #6 on: July 24, 2014, 10:06:08 AM »
I've also noticed that while my UIRoot is set to 2D, my UICamera's Event Type is 3DUI, not 2DUI.  I don't see the documentation for those choices, so not sure whether that could be relevant here.  I tried switching it, but lots of stuff broke, so I switched it back.

I also do quite a bit of activating/deactivating UI elements so it would be good to confirm the most up to date way to do that.  For example, I remember there used to be NGUITools.setactive prior to Unity 4.5, but I now use UIwidget.gameobject.setactive(bool); to turn my widgets and their children on and off.  I hope that is still correct.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disappearing box colliders
« Reply #7 on: July 25, 2014, 01:50:11 AM »
3DUI = UI is using 3D colliders. 2DUI = UI is using 2D box colliders.

NGUITools.SetActive uses gameObject.SetActive under the hood, so yes it's fine.