Author Topic: Buttons not working in draggable panel  (Read 8442 times)

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Buttons not working in draggable panel
« on: September 21, 2013, 05:34:31 PM »
I finally got my draggable panel working and all is right with the world.  However, last night I tried to add some buttons to one of the windows and I can see them, but they don't actually do anything.  I read that windows shouldn't be "static" so I made sure that option wasn't selected, though I think it's off by default.  All GUI items are on the right layer as well.  I also added "Drag Panel Content" to each button and it still didn't work. 

Anyone have any suggestions as to why my buttons don't work at all in the plane?  I assume something is wrong, but I'm not sure what it is.  Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Buttons not working in draggable panel
« Reply #1 on: September 21, 2013, 09:25:53 PM »
Turn on debugging on your UICamera then hover over the area. it will tell you what's intercepting the event.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #2 on: September 22, 2013, 02:35:18 AM »
Turn on debugging on your UICamera then hover over the area. it will tell you what's intercepting the event.

Thanks for the tip, there was a bounding box that was there and it was messing things up.  I removed it and it now shows that I'm clicking on the object.

However, the widgets still don't animate.  They won't change color, move (scale), etc.  I put a Drag Panel Contents script on the buttons.  They still don't animate.  Is there something I'm missing?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Buttons not working in draggable panel
« Reply #3 on: September 22, 2013, 03:25:27 AM »
How should they animate? Drag panel contents makes it possible to drag a panel when it's placed on a collider and references a draggable panel. There is no animation present.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #4 on: September 22, 2013, 04:08:46 AM »
How should they animate? Drag panel contents makes it possible to drag a panel when it's placed on a collider and references a draggable panel. There is no animation present.

I mean, my buttons won't animate.  I have an inventory setup with a lot of slots for items and each "button" is supposed to highlight (change color).  However, none of them animate at all.  Not sure why they won't change color, but something isn't right.  This is why I was asking if there was something else I needed to know about how draggable panels work with other buttons on them.  Sorry if I wasn't clear before.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Buttons not working in draggable panel
« Reply #5 on: September 22, 2013, 04:12:44 AM »
There is nothing special there. As long as the button has a collider, and UICamera shows the mouse hovering over that collider, you can expect the Button script to react appropriately.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #6 on: September 22, 2013, 04:18:07 AM »
There is nothing special there. As long as the button has a collider, and UICamera shows the mouse hovering over that collider, you can expect the Button script to react appropriately.

Okay.  Then something is wrong.  I created the backpack with some slots in it.  Each one has it's own collider, yet UICamera doesn't show anything over each slot.  It's as if each item doesn't have a collider at all.  However, if I add the prefab manually, it works for that item.  Is something changed if an item is cloned?

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #7 on: September 23, 2013, 01:06:43 AM »
Wanted to add to this that it seems like all items except a few in my backpack panel will not act as buttons even though they have the correct scripts attached.  I've been trying to do some debugging, but I can't find the problem.  If I put the buttons anywhere outside of the panel it they work fine.  However, inside the draggable panel they don't work.

I feel like there's a key point about NGUI that I'm missing.  Has anyone had this problem before?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Buttons not working in draggable panel
« Reply #8 on: September 23, 2013, 07:28:16 AM »
You likely have them on the wrong layer. NGUITools.AddChild sets the layer to match the parent.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #9 on: September 23, 2013, 10:16:25 AM »
Just checked.  Everything is on the same GUI layer. 

I just upgraded to 3.0 and the problem is still there.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Buttons not working in draggable panel
« Reply #10 on: September 23, 2013, 04:16:37 PM »
And the size of your collider is...?

Unless it matches the size of your widget, it won't work. Update it via ALT+SHIFT+C.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #11 on: September 23, 2013, 05:34:15 PM »
And the size of your collider is...?

Unless it matches the size of your widget, it won't work. Update it via ALT+SHIFT+C.

Changing the size of the collider didn't work.  They're all the same size since it's a prefab.  Some work and some don't.  The widget is 32x32 and the box collider is 32x32.  They're in a 780x330 draggable panel.  The collider on the draggable panel is the same at 780x330.  The behavior seems strange to me since some of the buttons work and some don't.  No idea why this is happening and I'm out of ideas to try.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Buttons not working in draggable panel
« Reply #12 on: September 24, 2013, 02:26:53 AM »
That sounds all sorts of weird. I would normally say that you're hitting a different collider than the one you're expecting to hit, but if you're seeing it hit in the debug output, I'm not sure what's going on.

When it's "some work, some don't" it's usually a depth issue where they are on the same z position as the background collider for instance, then it's undefined which you'll actually hit.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Buttons not working in draggable panel
« Reply #13 on: September 24, 2013, 11:01:43 AM »
That sounds all sorts of weird. I would normally say that you're hitting a different collider than the one you're expecting to hit, but if you're seeing it hit in the debug output, I'm not sure what's going on.

When it's "some work, some don't" it's usually a depth issue where they are on the same z position as the background collider for instance, then it's undefined which you'll actually hit.

Thanks for this post.  Thank you, thank you, thank you!!

After reading this I got an idea which lead me to going back and looking at all of the colliders again.  There was nothing out of the ordinary, so I'm still not sure why some of the buttons ("inventory slots") were working and others weren't.  The data for all the buttons was the same and all of the buttons were created with the same prefab.  However, I decided to screw around with the colliders and finally got it working.  Seems like the Z axis on the window collider needed to be adjusted.  Now, I'm not sure if this is the correct way to deal with the problem, but by playing around with the numbers, I was able to get it working.

At some point, I may have to go back and look over the windows in more detail, but I'm satisfied with how it's working.  Thanks again for the information. 

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Buttons not working in draggable panel
« Reply #14 on: September 24, 2013, 03:53:02 PM »
Happy to help.